Sponsored
Use these hints if you're stuck. Try solving on your own first.
Try all the possibilities of closing branches.
On the vertices that are not closed, use Floyd-Warshall algorithm to find the shortest paths.
Solve with full IDE support and test cases