Data Structures & AlgorithmsHardICPC regional · Codeforces Div 2 D
Directed weighted graph on vertices 0 to 5 with edges (u→v (w)): 5→0 (5), 1→4 (7), 0→1 (5), 2→1 (1), 2→5 (9), 2→0 (2), 5→2 (1), 0→3 (9), 1→3 (7), 4→2 (6), 0→5 (6), 1→5 (9), 1→2 (6). 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. 176
- B. 73
- C. 174
- D. 25
Correct answer: A. 176
Floyd–Warshall (checked against Dijkstra from every source) gives a total of 176. Adding only the direct edge weights gives 73, and ignoring edge directions gives 174; the reachable pair count 25 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 4 with edges (u→v (w)): 0→3 (7), 2→4 (1), 1→4 (5), 3→2 (5), 4→0 (3), 1→2 (8). Compute the sum of…
- Directed weighted graph on vertices 0 to 3 with edges (u→v (w)): 2→1 (2), 0→1 (7), 1→2 (5), 1→3 (1), 1→0 (5). Compute the sum of the…
- Directed weighted graph on vertices 0 to 4 with edges (u→v (w)): 2→3 (2), 0→3 (1), 0→4 (4), 0→2 (2), 3→1 (5), 2→0 (5), 3→0 (9), 4→2 (9)…
- Directed weighted graph on vertices 0 to 3 with edges (u→v (w)): 3→0 (5), 2→1 (8), 2→0 (8), 0→1 (9). Compute the sum of the shortest-path…
- Directed weighted graph on vertices 0 to 5 with edges (u→v (w)): 2→1 (3), 3→0 (3), 1→2 (1), 0→4 (5), 0→2 (3), 1→0 (5), 2→3 (7), 0→1 (3)…
- Directed weighted graph on vertices 0 to 3 with edges (u→v (w)): 1→3 (7), 1→2 (7), 3→2 (6), 3→0 (7), 2→3 (9), 2→0 (6), 3→1 (2). Compute…