Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div 2 D

Directed weighted graph on vertices 0 to 5 with edges (u→v (w)): 5→2 (4), 0→3 (4), 1→2 (7), 3→4 (3), 4→0 (9), 5→1 (4), 3→5 (8). 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. 39
  2. B. 292
  3. C. 210
  4. D. 18

Correct answer: C. 210

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic