Data Structures & AlgorithmsHardCodeforces Div2 D · GATE CS

A rooted tree has these parent→child edges: 11→33, 42→77, 42→70, 46→15, 70→46, 70→76, 42→16, 42→89, 31→11, 42→31, 76→67. The nodes carry these weights: node 11: 15; node 15: 20; node 16: 14; node 31: 8; node 33: 15; node 42: 18; node 46: 11; node 67: 14; node 70: 14; node 76: 5; node 77: 10; node 89: 5. A set of nodes is independent if no two chosen nodes are joined by an edge. What is the largest total weight of an independent set?

  1. A. 67
  2. B. 149
  3. C. 49
  4. D. 100

Correct answer: D. 100

Tree DP: for each node, either take it (children must be skipped) or skip it (children are free). Greedily taking the heaviest node, taking everything, or taking alternate depths are the trap answers.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic