Adjacency List Traversal


You are given an undirected graph with vertices numbered from 11 to nn. Starting at vertex ss, run a breadth-first search.

When a vertex has multiple unvisited neighbors available, smaller-numbered vertices must be visited first. To do this, sort each adjacency list before running the search.

Input

The first line contains three integers nn, mm, and ss, the number of vertices, the number of edges, and the starting vertex.

The next mm lines each contain two integers aa and bb, meaning there is an undirected edge between vertices aa and bb.

Output

Output one line containing the vertices in the order they are first visited by the BFS, separated by spaces.

Constraints

  • 1≤n≤2000001 \le n \le 200000
  • 0≤m≤3000000 \le m \le 300000
  • 1≤s≤n1 \le s \le n
  • 1≤a,b≤n1 \le a, b \le n

Example 1

Input 1
5 5 1
1 2
1 3
2 4
3 4
4 5
Output 1
1 2 3 4 5
Explanation

The BFS starts at 11. Vertices 22 and 33 are reached first, and vertex 22 is visited before vertex 33 because it has the smaller number.

Example 2

Input 2
6 5 4
4 2
4 6
2 1
2 3
6 5
Output 2
4 2 6 1 3 5
Explanation

From vertex 44, the sorted neighbors are 22 and 66. Vertex 22 is processed first, but vertex 66 was already discovered before vertices 11 and 33.

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.