问题3723--Kids’ Wishes

3723: Kids’ Wishes

[命题人 : ]
时间限制 : 3.000 sec  内存限制 : 64 MB

题目描述

Kevin is a kid. He has lunch at school together with many more kids. They use to go outdoors and have lunch sitting on the ground. They love to form a big circle in which each kid has exactly two neighbors, one on the left and one on the right. Sometimes the teacher has problems arranging the circle because some kids wish to sit down next to other kids. Each kid may wish to sit down next to at most two other kids, because each kid has just two neighbors in the circle. The teacher wants to know whether it is possible to arrange the circle in such a way that all kids’ wishe are satisfied. You clean up the place when the lunch ends. Since you want to finish your work as early as possible, help the teacher in answering that question.

输入

Each test case is given using several lines. The first line contains two integers K and W representing respectively the number of kids (3 <= K <= 10^9) and the number of wishes (0 <= W <= 10^5). Kids are identified with numbers between 1 and K. Each of the next W lines describes a different wish using two distinct integers A and B (1 <= A,B <= K); these values represent that kid A wishes to sit down next to kid B. Each kid has at most two wishes. The last test case is followed by a line containing two zeros.

输出

For each test case output a single line containing an uppercase ‘Y’ if it is possible to arrange a circle in such a way that all kids’ wishes are satisfied, or an uppercase ‘N’ otherwise.

样例输入 Copy

4 3
2 3
1 3
2 1
1000000000 0
3 6
3 2
2 1
1 2
1 3
2 3
3 1
0 0

样例输出 Copy

N
Y
Y

来源/分类