A proper vertex coloring is a labeling of the graph’s vertices with colors such that no two vertices sharing the same edge have the same color. A coloring using at most k colors is called a (proper) k-coloring.
Now you are supposed to tell if a given coloring is a proper k-coloring.
Input Specification:
Each input file contains one test case. For each case, the first line gives two positive integers N and M (both no more than
After the graph, a positive integer K (≤ 100) is given, which is the number of colorings you are supposed to check. Then K lines follow, each contains N colors which are represented by non-negative integers in the range of int. The i-th color is the color of the i-th vertex.
Output Specification:
For each coloring, print in a line k-coloring if it is a proper k-coloring for some positive k, or No if not.
Sample
Input:
1 | 10 11 |
Output:
1 | 4-coloring |
Solution
实际上考察的是图的遍历,这里采用的是无向图的邻接表的存法,BFS (类似于)
Code
1 |
|
- 本文标题:1154 Vertex Coloring (25分)
- 本文作者:codeflysafe
- 创建时间:2020-03-13 14:26:26
- 本文链接:https://codeflysafe.github.io/2020/03/13/2020-03-13-1154-Vertex-Coloring-(25分)/
- 版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!