Data Structures & AlgorithmsHardICPC regional · Codeforces Div 2 D

Directed weighted graph on vertices 0 to 5 with edges (u→v (w)): 3→0 (9), 4→5 (2), 1→3 (9), 1→2 (6), 5→2 (5), 3→1 (5), 0→1 (2), 2→3 (4), 4→0 (1), 1→4 (4), 2→0 (5). 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. 52
  2. B. 142
  3. C. 30
  4. D. 226

Correct answer: D. 226

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic