eolymp
bolt
Try our new interface for solving problems
Problems

Circular route

Circular route

In one country \textbf{N} cities connected by a network of roads. Network such that from every city you can reach any other, moving along the roads. The President has decided to follow in the footsteps of Franklin Delano Roosevelt and the unemployed to take a road construction, but building materials for new roads in sufficient numbers were not available, and decided to dismantle part of the old roads to improve the remaining roads. The President wants to remove the few roads that form a ring route (cycle) so that the remaining roads could still get from each city in each. Locate a circular route, or say that it does not exist. \InputFile The first line contains two integers \textbf{N} and \textbf{M}, the number of cities and roads, respectively (\textbf{1 }<= \textbf{N} <= \textbf{100 000}, \textbf{2N} <= \textbf{M} <= \textbf{3N}). In the following \textbf{M} lines are given road. Each road sets the number of cities, which it connects. Cities are indexed by numbers from \textbf{1} to \textbf{N}. Between the two cities may be several roads, the road can also connect the city with itself. \OutputFile Derive the number of \textbf{--1}, if desired route does not exist. If it exists, output a number of cities, forming the route.
Time limit 5 seconds
Memory limit 64 MiB
Input example #1
4 8
1 2
1 3
1 4
1 2
1 3
1 4
2 3
4 3
Output example #1
3 1 2 3
Author Pevel Kuznecov