Nothing Everything
Time limit1sMemory limit1024 MB
Decide whether a graph can be built by adding each vertex either isolated or joined to all earlier vertices, and output the operations if it can.
- Level
Medium5 of 10
- Topics
- Graph, Greedy, Implementation
- Solved
- No attempts yet
Problem
A undirected graph has vertices and edges. At the start, the graph contains only vertex . Determine whether can be built by performing the following two operations times, and if it can, print the sequence of operations in order.
- If the -th operation is Nothing, add vertex with no edges connecting it to any other vertex.
- If the -th operation is Everything, add vertex and connect it with an edge to every vertex from to .
Input
The first line contains and , separated by a space.
Each of the next lines contains and , separated by a space. This means that graph has an edge between vertex and vertex . Graph has no duplicate edges.
Output
If can be built with the two operations, print on the first line a string of length consisting only of N and E. The -th character is N if the -th operation is Nothing, and E if it is Everything. If there are several valid sequences, print any one of them.
If cannot be built, print -1.