Counter-manifestation
Time limit3.5sMemory limit256 MB
Given a directed road graph, check whether it contains a cycle, and list every junction that all cycles must pass through.
- Level
Medium7 of 10
- Topics
- Graph, DFS, Divide and conquer
- Solved
- No attempts yet
Problem
As every year, The Equality Parade takes place in Bytebury. It is an event during which individuals sharing a belief that for each language , for which there exists a non-deterministic Turing machine recognizing in a polynomial number of steps, there is also a deterministic Turing machine that recognizes the language in a polynomial number of steps, manifest their views publicly.
Previous editions of the parade proceeded peacefully: participants shouted "3-SAT is easy!" at most or raised banners presenting pseudo-code of the latest polynomial "algorithms" for finding the Hamiltonian cycle. However, this drew little interest from passers-by. This year, the parade organizers have decided to focus the attention of Bytebury residents and plan to chant more shocking slogans (which are somewhat true if ), including "Our money is not safe!" and "Our privacy is threatened!".
The Bytebury Security Bureau (BSB) fears that these slogans may cause an overwhelming majority of Bytebury residents to withdraw money from the banks and delete the social media accounts that BSB uses for population surveillance. Put plainly, the situation in Bytebury might become quite unstable.
To prevent this destabilization, BSB officers intend to organize a counter-manifestation promoting the belief in the inequality . At the same time, they plan to peacefully block the parade. BSB intends to start the counter-manifestation suddenly, at one of the junctions located on the parade's route. Unfortunately, the exact route of the Equality Parade is kept secret until the very end, so the Bureau needs to prepare the place for the counter-manifestation in advance. BSB only knows that the parade will start at some junction, pass through a non-zero number of roads, and finally return to the starting point. Your first task is to verify this information, that is, to check whether the Bytebury road network allows such a route to exist. Also, the agents want to know whether there are any junctions that the parade has to pass through, assuming the information is confirmed. They asked you to find all such junctions. One of them will be chosen as the most convenient location for the counter-manifestation. If no such junction exists, BSB will proceed to Plan B.
Input
The first line of input contains two integers and (, ), the number of junctions and the number of roads in Bytebury, respectively. The junctions are numbered through . The following lines describe the roads. The -th of these lines contains two integers and (, ), meaning that the -th road leads from junction to junction . No ordered pair appears more than once in the input.
Output
If the parade cannot be routed in accordance with the information known to BSB, the output is a single line containing the word "NIE" (Polish for "no"). Otherwise, the output has two lines. The first line contains the number of junctions that the parade's route will certainly pass through. The second line contains those junctions in ascending order. If , the second line is left blank.