Depth-First Search of an Undirected Graph
Run depth-first search from s in an undirected graph. Always visit the smallest available neighbor first.
Input
The first line contains n, m, and s. The next m lines contain undirected edges.
1 <= s <= n <= 10000 <= m <= n(n-1)/2
Output
Print the visited vertices in DFS order on one line.
Example
Input
6 5 1
1 3
1 2
2 4
3 5
5 6
Output
1 2 4 3 5 6
Comments