Depth-First Search of an Undirected Graph


Submit solution

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

Author:
Problem types

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

There are no comments at the moment.