Sponsored
Use these hints if you're stuck. Try solving on your own first.
Maintain the graph and use an efficient shortest path algorithm after each update.
We use BFS/Dijkstra for each query.
Solve with full IDE support and test cases