BFS Shortest Distances


You are given an undirected graph with nn vertices numbered from 11 to nn, and a starting vertex ss.

Find the minimum number of edges needed to reach every vertex from ss. If a vertex cannot be reached, its distance is -1.

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

Print nn integers: the distances from ss to vertices 1,2,…,n1, 2, \ldots, n, in order. Print -1 for each unreachable vertex.

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 4 1
1 2
1 3
2 4
4 5
Output 1
0 1 1 2 3

Example 2

Input 2
6 2 4
2 4
5 6
Output 2
-1 1 -1 0 -1 -1
Explanation

Only vertex 22 is reachable from vertex 44 in this graph.

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.