Data Structures & AlgorithmsModerateICPC regional · Codeforces Div 2 D

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), 0→3 (3), 0→2 (7). 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. 47
  2. B. 184
  3. C. 162
  4. D. 20

Correct answer: C. 162

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic