Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div 2 D
Directed weighted graph on vertices 0 to 4 with edges (u→v (w)): 0→1 (9), 4→0 (6), 2→1 (5), 0→3 (9), 2→4 (8), 3→1 (8), 1→3 (9), 4→1 (7), 1→4 (2), 4→2 (6), 3→4 (1). Compute the sum of the shortest-path distances over every ordered pair (i, j) with i ≠ j where j is reachable from i. What is that sum?
- A. 70
- B. 167
- C. 114
- D. 20
Correct answer: B. 167
Floyd–Warshall (checked against Dijkstra from every source) gives a total of 167. Adding only the direct edge weights gives 70, and ignoring edge directions gives 114; the reachable pair count 20 is not a sum at all.
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 0 to 5 with edges (u→v (w)): 5→2 (4), 0→3 (4), 1→2 (7), 3→4 (3), 4→0 (9), 5→1 (4), 3→5 (8). Compute…
- Directed weighted graph on vertices 0 to 3 with edges (u→v (w)): 1→2 (8), 0→3 (8), 2→1 (8), 0→1 (8), 3→1 (6), 2→0 (3), 1→3 (8), 1→0 (6)…
- Array A = [3, 1, 1, 1, 5, 2, 1]. An increasing subsequence is chosen by INDEX positions i1 < i2 < … with A[i1] < A[i2] < … (strictly…
- Dictionary D = {bcm, bct, blr, erl, etm, ncm, nrl, ocl, prm, sco, sct, snl} (all words have 3 letters). Starting from the word 'ocm', a…
- Tree with vertices 0 to 9, root 0, edges 0–1, 1–2, 0–3, 2–4, 3–5, 0–6, 4–7, 3–8, 6–9 (parent–child). Vertex weights (vertex:weight) 0:19…
- Array A = [2, 4, 4, 1, 3, 5, 3, 5, 4]. An increasing subsequence is chosen by INDEX positions i1 < i2 < … with A[i1] < A[i2] < … (strictly…