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?
- A. 13
- B. 7
- C. 136
- 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.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Weighted tree on vertices 0 to 5 with edges 0–1 (9), 0–2 (8), 1–3 (4), 3–4 (4), 1–5 (3). What is the largest possible sum of edge weights…
- A binary tree with distinct letters has preorder DFEACB and inorder FDACEB. What is its postorder traversal (left, right, root), written…
- 5 × 5 grid, rows top to bottom ('#' = wall, '.' = open): ..... / ###.. / ....# / ...## / ##.#.. Start at top-left, target bottom-right…
- Points A(5,2), B(2,4), C(6,0), D(0,3), E(8,1) in the plane. The cost of joining two points is the Manhattan distance |x1−x2| + |y1−y2|…
- Undirected weighted graph on vertices A, B, C, D, E, F; its edges, in this listed order, are: B–D (8), A–E (3), C–D (8), A–C (3), C–F (4)…
- Directed weighted graph on vertices A, B, C, D, E with edges A→C (4); C→E (-2); D→C (-4); D→B (2); D→E (-1); D→A (1); E→D (6); E→C (-2)…