Loading...
Loading...
Loading...
Offices are joined by two-way links. Print how many offices are exactly k links away from office s, taking the fewest links needed to reach each office.
Example
Input
6 5 0 1 0 2 1 3 2 3 3 4 0 2
Output
1
Only office 3 is two links away.
Try the problem first. Open one hint at a time.
Run BFS to get the distance of every node.
Count the nodes whose distance equals k.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor