题目链接:1154 Vertex Coloring
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 $10^4$), being the total numbers of vertices and edges, respectively. Then $M$ lines follow, each describes an edge by giving the indices (from $0$ to $N−1$) of the two ends of the edge.
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 properk
-coloring for some positivek
, orNo
if not.
Sample Input 1:
1 | 10 11 |
Sample Output:
1 | 4-coloring |
题意
给定一个图,以及每个顶点的颜色,问是否所有边连接的两个顶点颜色不同。
思路
枚举每一条边即可。
代码
1 |
|