Below is an undirected graph:
Apply the BFS procedure for the graph using as a starting node. As an answer, print edges of the resulting spanning tree. Edges' order does not matter, but the two nodes of each edge must be in the order of motion (lower distance to higher distance). The last line of your answer should contain the shortest distance from to every node of the graph (nodes are sorted in alphabetical order, the shortest distance from to is 0).
Below is an example that clarifies the expected output format:
A B
B C
C D
0 1 2 3
Here, the first three lines correspond to three edges of a spanning tree (an edge from to , an edge from to and an edge from to ), while the last line corresponds to the shortest distance from the starting node to every node of the graph. The starting node is , the shortest distance from to is 0, from to – 1, from to – 2, from to – 3.