397. How Many at Each Distance
Print how many vertices sit at distance 0 from vertex 1, then how many at distance 1, then distance 2, and so on, stopping at the largest distance any vertex actually has.
Print the numbers on one line separated by single spaces.
Problem 371 asked for one distance and this asks for all of them at once, which is what breadth-first search naturally produces: it visits in order of distance, so the counts come out already grouped.
Vertex 1 is always at distance 0, so the first number is always 1. Vertices that cannot be reached appear nowhere at all, which is what the seventh test checks.
Constraints - `1 ≤ n ≤ 100000` - `0 ≤ m ≤ 200000` - There are no self-loops and no repeated edges.
Input
The first line contains two integers n and m, the number of vertices and
edges. Each of the next m lines contains two integers u and v, an
undirected edge between those vertices. Vertices are numbered 1 to n.
Output
Print the count at each distance, from 0 upward, on one line separated by single spaces.