#P6066. Eulerian Patrol
Eulerian Patrol
Eulerian Patrol
Farmer John has \(N\) farms (\(2 \leq N \leq 10^4\)) connected by \(M\) roads (\(1 \leq M \leq 5 \times 10^4\)). Note that there may be multiple roads connecting the same pair of farms.
Bassie starts patrolling from farm \(1\). For every road, he must traverse it in both directions exactly once and finally return to farm \(1\). In other words, if a road connects farms \(u\) and \(v\), you have to use both the edge \(u \to v\) and the edge \(v \to u\) exactly one time.
It is guaranteed that such a path exists. If there are multiple valid paths, any one is acceptable.
inputFormat
The first line contains two integers \(N\) and \(M\), separated by a space.
Each of the next \(M\) lines contains two integers \(u\) and \(v\) representing a road between farms \(u\) and \(v\).
outputFormat
Output a single line containing the sequence of farms (vertices) representing the Eulerian circuit. The circuit must start and end at farm \(1\), and the vertices should be separated by a space.
sample
2 1
1 2
1 2 1