Data Structures & AlgorithmsHardCodeforces Div 2 · ICPC regional
Directed weighted graph on vertices A, B, C, D with edges (u→v, w): D→B (3); B→C (4); A→C (6); D→A (2); A→D (2); D→C (6); B→A (8); B→D (8). 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. 9
- B. 44
- C. 25
- D. 3
Correct answer: B. 44
Floyd–Warshall gives the reachable ordered pairs, and their distances add up to 44. The number of unreachable pairs (3) and the count of reachable pairs (9) 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
- Directed weighted graph on vertices A, B, C, D, E, F with edges listed in this exact order: E→D (1); F→D (5); F→C (1); B→E (5); F→A (4)…
- Coins of denominations [12, 9, 8, 2] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 18?…
- Array A = [9, 3, 3, 8, 2, 4, 3] (indices 0 to 6). Count the non-empty subsets of positions (each position used at most once, subsets not…
- Rooted tree with root 0 and vertices 0 to 9; the edges are 0–1, 1–2, 1–3, 0–4, 2–5, 5–6, 1–7, 2–8, 6–9 (parent–child). Every edge has…
- A binary tree with distinct letters has preorder ABEDCF and inorder ECDFBA. What is its postorder traversal (left, right, root), written…
- Directed acyclic graph on vertices A, B, C, D, E, F (every edge goes from a smaller to a larger letter) with weighted edges A→D (9), A→E…