Data Structures & AlgorithmsHardGATE CS · ICPC regional
Directed weighted graph on vertices A, B, C, D with edges (u→v, w): C→A (2); D→B (1); C→D (7); B→A (5); B→D (5); A→B (8); D→A (3); C→B (6). 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. 50
- B. 3
- C. 33
- D. 9
Correct answer: A. 50
Floyd–Warshall gives the reachable ordered pairs, and their distances add up to 50. 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
- Rooted tree with root 0 and vertices 0 to 9; the edges are 0–1, 0–2, 1–3, 1–4, 4–5, 3–6, 3–7, 3–8, 4–9 (parent–child). Every edge has…
- Undirected graph on vertices A, B, C, D, E, F, G with weighted edges A–B (4), A–C (4), B–D (1), C–D (5), C–E (5), C–F (8), C–G (1), D–F…
- Undirected weighted graph on vertices A, B, C, D, E with edges A–B (2), A–C (3), B–D (2), B–E (1), C–E (1), D–E (2). An edge is CRITICAL…
- Rooted tree with root 0 and vertices 0 to 9; the edges are 0–1, 1–2, 1–3, 3–4, 2–5, 5–6, 6–7, 3–8, 3–9 (parent–child). Every edge has…
- Coins of denominations [12, 10, 2] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 20?…
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–D (1), A–F (1), A–G (1), B–G (1), C–F (1), C–G (1), D–E (1), D–F (1)…