Depth-First Search of a Directed Graph


Submit solution

Points: 100
Time limit: 2.0s
Memory limit: 256M

Author:
Problem types

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 <= 1000
  • 0 <= 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

There are no comments at the moment.