Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div 2 D

Directed weighted graph on vertices 0 to 3 with edges (u→v (w)): 1→2 (8), 0→3 (8), 2→1 (8), 0→1 (8), 3→1 (6), 2→0 (3), 1→3 (8), 1→0 (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. 55
  2. B. 84
  3. C. 12
  4. D. 108

Correct answer: D. 108

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic