Euler Tours
View as PDFProblem Statement
You are given an undirected connected graph with vertices and
edges. Output the Euler Tour order of this graph of the graph starting at node
. If you have a choice to visit more than one child, visit the child with the lowest value/label.
You only need to record the first and last visits to a node in your Euler Tour.
Input Format
Your first line will contain a single integer .
Your next
lines will contain two space-separated integers each
and
representing an edge from
to
.
Output Format
You should output ordering of the vertices along an Euler tour of the graph starting at node .
Constraints
and
Template
import sys
sys.setrecursionlimit(int(1e9))
n = int(input())
edges = [map(int, input().split()) for _ in range(n - 1)]
# print your output
Sample Cases
Input 1
8
1 2
2 3
2 4
1 5
5 6
6 7
6 8
Output 1
1 2 3 3 4 4 2 5 6 7 7 8 8 6 5 1
Input 2
10
3 10
3 5
1 3
5 7
2 5
2 4
5 8
6 8
6 9
Output 2
1 3 5 2 4 4 2 7 7 8 6 9 9 6 8 5 10 10 3 1
Comments