Data Structures & AlgorithmsHardGATE CS · ICPC regional
Directed weighted graph on vertices A, B, C, D, E with edges (u→v, w): A→D (3); E→D (4); A→E (3); C→A (8); A→C (5); D→C (6); E→C (9); B→E (7); B→A (1). 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. 64
- B. 16
- C. 4
- D. 123
Correct answer: D. 123
Floyd–Warshall gives the reachable ordered pairs, and their distances add up to 123. The number of unreachable pairs (4) and the count of reachable pairs (16) 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
- Distinct keys [26, 13, 5, 17, 19, 4] are inserted, in the order given by the sequence [19, 13, 4, 5, 17, 26], into an empty binary search…
- Undirected simple graph on vertices A, B, C, D, E, F with edges A–C (1), A–D (1), A–F (1), B–D (1), B–E (1), D–E (1), E–F (1) (weights…
- Connected undirected weighted graph on vertices A, B, C, D, E with edges A–B (1), A–D (4), A–E (4), B–C (4), B–D (1), B–E (3), D–E (2)…
- Tree with vertices 0 to 9, root 0, edges 0–1, 0–2, 2–3, 1–4, 3–5, 4–6, 5–7, 4–8, 8–9 (parent–child). Vertex weights (vertex:weight) 0:18…
- Keys [19, 23, 15, 12, 48, 41] are inserted, in this order, into an empty AVL tree using the standard rebalancing (left, right, left–right…
- A binary tree with distinct letters has preorder FECBDGA and inorder CDGBEAF. What is its postorder traversal (left, right, root), written…