Task
You are given an undirected graph with vertices and edges, as well as a vertex . Find the length of the shortest path between and all the vertexes from the graph, including itself.
We define the shortest path between two vertices and as the smallest number of edges on a chain that connects and .
Input data
The first line will contain three numbers, , and , representing the number of vertices and edges the graph has, as well as the starting vertex. The next lines will contain the description of the graph, with one edge on each line.
Output data
The first line will contain numbers, representing the lengths of the shortest path between and every other node from the graph. If there is a node that cannot be accessed from , we will print for that vertex.
Constraints and clarifications
- ,
- There are no two identical edges.
- For tests worth points, .
Example
stdin
5 5 3
1 2
1 3
1 4
2 3
5 4
stdout
1 1 0 2 3