Data Structures & AlgorithmsHardICPC regional · Codeforces Div 2 D

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

Correct answer: C. 68

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic