Data Structures & AlgorithmsHardCodeforces Div 2 C
Tree on vertices 0 to 8 with weighted edges (u–v (w)): 3–5 (6), 2–7 (4), 0–6 (3), 6–8 (6), 2–3 (6), 0–1 (3), 0–2 (8), 4–6 (8). What is the diameter of the tree, i.e. the largest sum of edge weights over any path between two vertices?
- A. 20
- B. 5
- C. 31
- D. 44
Correct answer: C. 31
The heaviest path has weight 31, confirmed by all-pairs distances. The eccentricity of vertex 0 (20) measures paths from a single vertex, and the hop-count diameter (5) 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 7 with weighted edges (u–v (w)): 4–6 (2), 0–2 (1), 5–7 (3), 1–2 (9), 4–7 (7), 1–6 (8), 2–3 (5). What is the diameter…
- Simple undirected graph on vertices 0 to 5 with edges: 1–3, 0–3, 4–5, 2–5, 3–4, 1–5, 0–5. How many spanning trees does it have (edge…
- Simple undirected graph on vertices 0 to 4 with edges: 3–4, 0–2, 0–3, 2–4, 0–1, 1–2, 1–3. How many spanning trees does it have (edge…
- Simple undirected graph on vertices 0 to 4 with edges: 2–4, 1–4, 0–2, 2–3, 1–2, 0–4, 0–3, 0–1, 1–3. How many spanning trees does it have…
- Simple undirected graph on vertices 0 to 4 with edges: 0–3, 0–2, 1–2, 1–3, 1–4, 2–4, 2–3, 0–1. How many spanning trees does it have (edge…
- Simple undirected graph on vertices 0 to 3 with edges: 0–2, 2–3, 1–2, 0–3, 1–3, 0–1. How many spanning trees does it have (edge subsets…