题目描述
Bob wants to assign frequencies to n satellites, numbered from 0 to n − 1. Two distinct satellites are said to be adjacent if, when assigned the same frequency, they interfere with each other. Sensibly, Bob’s assignment of frequencies must avoid interference altogether.
However, only three frequencies are available to him.
Please determine whether Bob can assign frequencies to all satellites to avoid any interference.
输入
The first line of the input contains an integer indicating the number of input cases. For each test case, the first line contains an integer n, denoting the number of satellites. The second line contains an integer p, denoting the number of adjacent pairs of satellites. The next p lines each contains two integers i, j, indicating the satellite i may intefer with satelite j when both are assigned the same frequency.
输出
For each test case, output “Y” if Bob can assign frequences so there is no integerence. Output “N” otherwise.
样例输入
4 6 6 0 3 1 5 3 2 2 5 0 4 1 0 7 12 6 5 0 3 2 6 3 5 5 0 0 4 4 5 6 3 1 4 1 2 3 4 2 3 7 8 6 5 0 3 2 6 3 5 1 4 1 2 3 4 2 3 6 9 0 1 1 2 2 3 5 2 5 3 3 4 2 4 1 4 4 5
样例输出
Y N Y
提示
1. There are at most 85 test cases
2. The number of satellites is n, n ≤ 25.
思路:DFS