eolymp
bolt
Try our new interface for solving problems
Problems

Fire safety

Fire safety

There are $n$ houses in the city of Zelenograd. Some of them are connected by one-way roads. In recent times in Zelenograd the incidents of fires have increased. In this regard, the residents decided to build several fire stations in the city. But there was a problem - the fire engine traveling on the call, of course, can ignore the direction of the current road, however, the car returning from the job is obliged to follow the traffic rules (the people of Zelenograd piously respect these rules!). It is clear that wherever the fire truck will be, it should be possible to return to the fire station where from it started its way. But the construction of stations costs a lot of money, so at the city council it was decided to build a minimum number of stations in such a way that this condition was hold. In addition for saving money, it was decided to build stations in the form of extensions to existing houses. Your task is to write a program that calculates the optimal position of the stations. \InputFile First line contains the number of houses $n~(1 \le n \le 3000)$. Second line contains the number of roads $m~(1 \le m \le 10^5)$. Then the description of the roads is given in format $a_i~b_i$ meaning that it is allowed for the cars to move along the road $i$ from the house $a_i$ to the house $b_i~(1 \le a_i, b_i \le n)$. \OutputFile In the first line print the minimum number of fire stations $k$ that must be built. In the second line print $k$ numbers in random order --- the houses where you need to attach the fire stations. If there are several optimal solutions, output any. \includegraphics{https://static.e-olymp.com/content/70/70056caf613683d74eae3940063319c11b97ba73.gif}
Time limit 1 second
Memory limit 128 MiB
Input example #1
5
7
1 2
2 3
3 1
2 1
2 3
3 4
2 5
Output example #1
2
4 5
Author Vitaly Goldstein
Source 2011 Winter School, Kharkov, Day 9