Data Structures & AlgorithmsHardGATE CS · ICPC regional
Tree with vertices 0 to 6, root 0, edges 0–1, 1–2, 1–3, 1–4, 2–5, 5–6 (parent–child). Vertex weights (vertex:weight) 0:18, 1:5, 2:11, 3:9, 4:15, 5:12, 6:11. Choose a set of vertices with no two adjacent in the tree that maximises the total weight. What is that maximum total weight?
- A. 64
- B. 46
- C. 54
- D. 17
Correct answer: A. 64
Tree DP with take/skip states gives 64. Greedily taking the heaviest vertices first gives 54, and the minimum vertex cover weight 17 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
- Array A = [7, 14, 10, 21, 3, 17, 9, 20, 26]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 19? (A trie with subtree counts answers…
- Undirected graph on vertices A, B, C, D, E, F, G with edges A–C (1), A–D (1), B–D (1), B–E (1), B–F (1), B–G (1), C–D (1), C–G (1), D–E…
- Connected undirected weighted graph on vertices A, B, C, D, E with edges A–B (5), A–E (2), B–E (2), C–D (6), C–E (3), D–E (6). Among all…
- Bipartite graph with left side {A, B, C}, right side {D, E, F} and edges A–D, A–E, B–F, C–D, C–F. What is the size of a maximum matching…
- A binary trie of 6-bit numbers stores the set S = [12, 44, 27, 7, 63, 30, 48]. For the query x = 39, what is the maximum value of x XOR s…
- Array A = [20, 5, 12, 11, 18, 29, 30, 31, 17]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 9? (A trie with subtree counts answers…