The shortest path
Very easy
Execution time limit is 2 seconds
Runtime memory usage limit is 128 megabytes
The undirected graph is given. Find the shortest path from vertex a to vertex b.
Input
The first line contains two integers n and m (1 ≤ n ≤ 5 * 10^4
, 1 ≤ m ≤ 10^5
) - the number of vertices and edges. The second line contains two integers a and b - the starting and ending point correspondingly. Next m lines describe the edges.
Output
If the path between a and b does not exist, print -1. Otherwise print in the first line the length l of the shortest path between these two vertices in number of edges, and in the second line print l + 1 numbers - the vertices of this path.
Examples
Input #1
Answer #1
Input #2
Answer #2
Submissions 10K
Acceptance rate 40%