A courier must traverse every directed route exactly once. Print an Euler trail from node 1 to node n, or -1 if impossible.
Input: n m then m directed edges. Output the m+1 vertex trail, or -1.
Example 1:
Input: 3 3
1 2
2 1
1 3
Output: 1 2 1 3
Example 2:
Input: 2 1
1 2
Output: 1 2
Example 3:
Input: 3 2
1 2
2 3
Output: 1 2 3
Constraints:
2≤n≤200000; m≤300000; trail must begin at 1 and end at n.
Tags:
graphs eulerian-path hierholzer
Loading...
Test Cases:No test cases
No test cases available.
Tikki Upstream’s Euler Dispatch - HARD Coding Problem | CodeTikki