Depth-First Search Traversal
Perform a DFS traversal of a graph starting from a given node.
Input format
The first line contains N, M, and SRC. The next M lines contain edge pairs (undirected).
Output format
Print recursive DFS traversal starting from SRC, ascending neighbors.
Constraints
- Values fit in a 64-bit signed integer
- Trailing whitespace and a trailing newline are ignored by the judge
Read from stdin, write to stdout. Sample cases below show the exact format.
Sample cases
Example 1
Input
24 18 13
2 16
10 17
18 23
17 23
13 18
4 11
5 18
4 19
13 23
14 19
5 19
3 20
9 13
10 22
0 11
0 3
12 14
2 18Expected output
13 9 18 2 16 5 19 4 11 0 3 20 14 12 23 17 10 22Example 2
Input
2 1 1
0 1Expected output
1 0