Data Structures & AlgorithmsHardICPC regional · Codeforces Div 2 D

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

Correct answer: D. 162

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic