#P4429. [BJOI2018] 染色
[BJOI2018] 染色
Description
pupil likes coloring the vertices of a graph. One day, master wanted to make things difficult and gave him a simple undirected graph (no multiple edges or self-loops). For each vertex, master assigned a color set of size , and pupil can only choose one color from that set for the vertex. master wants pupil’s coloring to be such that no two vertices connected by an edge are colored with the same color.
Now pupil wants to know whether, no matter what color sets master assigns, he can always color the graph as required.
Input Format
The input contains multiple test cases.
The first line contains a positive integer , the number of test cases.
For each test case, the first line contains two space-separated integers , the number of vertices and edges in the undirected graph.
Then follow lines, each containing two space-separated positive integers , indicating an edge between vertices and .
Vertices are numbered from .
Output Format
For each test case, if pupil can always color the graph regardless of the assigned color sets, output a line with the string YES; otherwise, output a line with the string NO.
3
6 9
1 2
1 4
1 6
3 2
3 4
3 6
5 2
5 4
5 6
2 1
1 2
3 3
1 2
1 3
2 3
NO
YES
NO
Hint
Sample explanation.
For the first test case, if the sets for the first and second vertices are , for the third and fourth vertices are , and for the fifth and sixth vertices are , then the odd-indexed vertices must use at least two colors, and the even-indexed vertices must use at least two colors. Therefore, at least one odd-indexed vertex and one even-indexed vertex share the same color. But there is an edge between every pair of odd-indexed vertices and between every pair of even-indexed vertices, so the requirement “no two adjacent vertices share the same color” cannot be satisfied.
For the second test case, regardless of the two sets, color the first vertex with any color from its set, and color the second vertex with a color from its set that is different from the first vertex’s color.
For the third test case, if all three vertices have the set , then the requirement “no two adjacent vertices share the same color” cannot be satisfied.
Constraints:
- For of the testdata, .
- For of the testdata, .
- For of the testdata, , .
- For of the testdata, , , .
- There are also unscored hack testdata.
Translated by ChatGPT 5
京公网安备 11011102002149号