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