Problem A. Breadth First Search
You are to write a program that receives an unweighted undirected graph and writes all its vertices in
order of increasing distance from given vertex S
Distance between vertices A and B is the length of the shortest path from A to B.
If there are several vertices such that their distances to S are equal,
they may be printed in arbitrary order.
Input file format
Input file contains three integers N, M and S.
Vertices are numbered with integer numbers from 1 to N. M is the number of edges,
S is the starting vertice.
Each of next M lines contain pair of integers — numbers of vertices connected by an edge.
Output file format
Output file must contain sequence of vertex numbers sorted by increasing distance from S.
If some vertex is not reachable from S, output must contain a single number −1.
0 ≤ N, M ≤ 100000
||Input file (
|Output file (|
3 2 1
1 2 3