Data Structures & AlgorithmsHardCodeforces Div 2 · ICPC regional
Tree with vertices 0 to 7, root 0, edges 0–1, 1–2, 2–3, 0–4, 2–5, 2–6, 4–7 (parent–child). Vertex weights (vertex:weight) 0:8, 1:6, 2:7, 3:2, 4:10, 5:3, 6:7, 7:13. Choose a set of vertices with no two adjacent in the tree that maximises the total weight. What is that maximum total weight?
- A. 23
- B. 33
- C. 31
- D. 28
Correct answer: B. 33
Tree DP with take/skip states gives 33. Greedily taking the heaviest vertices first gives 28, and the minimum vertex cover weight 23 is the complement, not the answer.
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
- Bipartite graph with left side {A, B, C, D}, right side {E, F, G, H} and edges A–G, B–F, B–G, C–E, C–H, D–E. What is the size of a maximum…
- Weighted tree on vertices 0 to 7 with edges 0–1 (4), 0–2 (2), 0–3 (8), 0–4 (5), 1–5 (8), 0–6 (4), 0–7 (2). What is the largest possible…
- 2 × 3 sliding puzzle with tiles 1 to 5 and one blank (shown as ). Current board: 2 4 3 / 1 5 . Goal board: 1 2 3 / 4 5 . A move slides a…
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–B (1), A–E (1), A–F (1), C–E (1), D–E (1), D–G (1), E–F (1), F–G (1)…
- Distinct keys [25, 10, 8, 14, 19] are inserted, in the order given by the sequence [19, 8, 14, 10, 25], into an empty binary search tree…
- Undirected weighted graph on vertices A, B, C, D, E with edges A–B (3), A–C (3), A–D (1), B–E (1), C–D (2), C–E (3). How many distinct…