Data Structures & AlgorithmsVery hardCodeforces Div 2 C
Tree on vertices 0 to 6 with weighted edges (u–v (w)): 5–6 (8), 1–6 (9), 2–6 (4), 1–4 (3), 0–6 (5), 1–3 (7). What is the diameter of the tree, i.e. the largest sum of edge weights over any path between two vertices?
- A. 21
- B. 24
- C. 3
- D. 36
Correct answer: B. 24
The heaviest path has weight 24, confirmed by all-pairs distances. The eccentricity of vertex 0 (21) measures paths from a single vertex, and the hop-count diameter (3) ignores the weights.
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
- Tree on vertices 0 to 8 with weighted edges (u–v (w)): 3–6 (9), 4–7 (7), 0–1 (1), 3–5 (7), 3–7 (4), 0–8 (5), 1–7 (8), 2–7 (1). What is the…
- Tree on vertices 0 to 5 with weighted edges (u–v (w)): 0–3 (5), 1–5 (5), 1–3 (9), 3–4 (6), 1–2 (5). What is the diameter of the tree, i.e…
- Tree on vertices 0 to 8 with weighted edges (u–v (w)): 7–8 (6), 2–8 (1), 3–6 (2), 0–5 (5), 0–1 (2), 0–6 (3), 4–5 (6), 0–7 (2). What is the…
- Tree on vertices 0 to 8 with weighted edges (u–v (w)): 5–6 (9), 3–8 (2), 0–2 (5), 0–4 (2), 3–5 (2), 1–2 (2), 0–8 (5), 3–7 (6). What is the…
- Tree on vertices 0 to 8 with weighted edges (u–v (w)): 2–5 (5), 1–2 (1), 3–8 (7), 1–4 (5), 5–6 (5), 1–8 (8), 0–7 (1), 0–6 (2). What is the…
- Tree on vertices 0 to 8 with weighted edges (u–v (w)): 1–8 (4), 2–6 (5), 4–8 (5), 3–6 (5), 2–8 (4), 2–7 (6), 0–8 (6), 1–5 (4). What is the…