Data Structures & AlgorithmsHardICPC regional · Codeforces Div 2 D

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), 5→1 (3), 0→5 (1), 0→2 (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?

  1. A. 48
  2. B. 280
  3. C. 138
  4. D. 30

Correct answer: B. 280

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic