Data Structures & AlgorithmsHardICPC regional · Codeforces Div 2 D
Directed weighted graph on vertices 0 to 4 with edges (u→v (w)): 4→3 (9), 2→0 (7), 1→2 (2), 3→0 (4), 2→3 (9), 3→2 (4), 1→0 (9), 4→1 (8), 2→4 (5), 3→4 (4), 4→0 (9). Compute the sum of the shortest-path distances over every ordered pair (i, j) with i ≠ j where j is reachable from i. What is that sum?
- A. 123
- B. 70
- C. 112
- D. 16
Correct answer: A. 123
Floyd–Warshall (checked against Dijkstra from every source) gives a total of 123. Adding only the direct edge weights gives 70, and ignoring edge directions gives 112; the reachable pair count 16 is not a sum at all.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Directed weighted graph on vertices 0 to 5 with edges (u→v (w)): 1→5 (5), 2→0 (6), 0→4 (6), 1→0 (4), 1→3 (2), 4→3 (4), 3→5 (6), 2→3 (2)…
- Directed weighted graph on vertices 0 to 5 with edges (u→v (w)): 3→2 (2), 1→2 (6), 4→3 (5), 5→1 (5), 2→3 (4), 5→0 (2), 3→0 (7), 0→1 (6)…
- Directed weighted graph on vertices 0 to 5 with edges (u→v (w)): 2→0 (9), 5→4 (3), 1→0 (1), 0→1 (8), 1→4 (8), 1→3 (7), 2→5 (3), 3→0 (7)…
- Directed weighted graph on vertices 0 to 5 with edges (u→v (w)): 5→4 (1), 3→2 (6), 4→3 (7), 3→5 (6), 0→2 (4), 5→0 (5), 0→5 (1), 4→0 (1)…
- Directed weighted graph on vertices 0 to 4 with edges (u→v (w)): 0→1 (9), 4→0 (6), 2→1 (5), 0→3 (9), 2→4 (8), 3→1 (8), 1→3 (9), 4→1 (7)…
- Directed weighted graph on vertices 0 to 5 with edges (u→v (w)): 5→2 (4), 0→3 (4), 1→2 (7), 3→4 (3), 4→0 (9), 5→1 (4), 3→5 (8). Compute…