Justice League
Time limit1sMemory limit128 MB
Decide whether the graph of heroes can be split into a clique and an independent set.
- Level
Medium6 of 10
- Topics
- Graph, Divide and conquer, Recursion, Brute force
- Solved
- No attempts yet
Problem
Thirty-five years ago, a group of super heroes came together to form the Justice League, whose purpose was to protect planet Earth from villains. After all those years helping mankind, its members are retiring, and now it is time to choose the new members of the Justice League.
To keep their identities secret, super heroes identify themselves with an integer. There are super heroes on Earth, numbered from to . If two super heroes have already worked together on a mission, we say the two heroes have a relationship.
There must be exactly one Justice League in the world, and it may be formed by any number of super heroes (even a single one). It must satisfy both of the following conditions.
- Any two heroes chosen for the League must have a relationship.
- Any two heroes not chosen for the League must not have a relationship. (This prevents the formation of unofficial justice leagues.)
In other words, you must decide whether the whole set of heroes can be partitioned into a League in which everyone is pairwise related, and a remaining set in which no one is related to anyone else.
Given the heroes and their relationships, determine whether it is possible to form the Justice League under the conditions above.
Input
The input consists of several test cases. The first line of each test case contains two integers separated by a single space, () and (), indicating the number of heroes and the number of relationships, respectively.
Each of the following lines contains two integers separated by a single space, and (), indicating that hero has a relationship with hero . Relationships are undirected, so if has a relationship with , then also has a relationship with . A relationship is never given twice within a test case.
The end of the input is indicated by a line with . The input is read from standard input.
Output
For each test case, print a single line containing the uppercase letter Y if it is possible to form the Justice League under the given conditions, or the uppercase letter N otherwise. The output is written to standard output.