Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2

Directed weighted graph on vertices A, B, C, D, E with edges (u→v, w): C→D (8); E→C (4); D→C (8); C→E (6); D→A (4); B→E (5). Let d(x, y) be the shortest-path distance from x to y, and consider every ORDERED pair (x, y) with x ≠ y for which y is reachable from x. What is the sum of d(x, y) over those pairs?

  1. A. 13
  2. B. 7
  3. C. 136
  4. D. 59

Correct answer: C. 136

Floyd–Warshall gives the reachable ordered pairs, and their distances add up to 136. The number of unreachable pairs (7) and the count of reachable pairs (13) are the wrong quantities.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic