Data Structures & AlgorithmsModerateICPC regional · Codeforces Div 2 D

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), 3→4 (8), 3→2 (6), 4→1 (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?

  1. A. 57
  2. B. 88
  3. C. 16
  4. D. 104

Correct answer: D. 104

Floyd–Warshall (checked against Dijkstra from every source) gives a total of 104. Adding only the direct edge weights gives 57, and ignoring edge directions gives 88; the reachable pair count 16 is not a sum at all.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic