count junctions numbered 0 to count - 1 and exactly count two-way roads: roads[i] = [a, b] connects junctions a and b. Every junction can reach every other one, and the network contains exactly one closed loop, the ring road.
The distance between two junctions is the smallest number of roads you need to drive along to get from one to the other.
Return an array of length count whose i-th element is the distance from junction i to the nearest junction on the ring road. Junctions on the ring itself get 0.count=6, roads=[[0, 1], [1, 2], [2, 0], [2, 3], [3, 4], [1, 5]] → [0, 0, 0, 1, 2, 1]
The ring is junctions 0, 1, 2. Junction 3 is one step from 2, junction 4 is two steps away, and junction 5 is one step from 1.
count=4, roads=[[3, 0], [0, 1], [1, 2], [2, 3]] → [0, 0, 0, 0]
All roads form a single ring, so every junction is already on it.
count=5, roads=[[4, 3], [3, 2], [2, 1], [1, 3], [0, 4]] → [2, 0, 0, 0, 1]
count ≤ 10⁵roads) = countcount, a ≠ bcount=6, roads=[[0, 1], [1, 2], [2, 0], [2, 3], [3, 4], [1, 5]]
[0, 0, 0, 1, 2, 1]
Run checks the first 3 tests in your browser. Submit checks all 37 tests on the server, hidden ones included.