Data Structures & AlgorithmsHardCodeforces Div2 D · GATE CS

A rooted tree has these parent→child edges: 73→27, 57→8, 84→26, 57→70, 92→84, 70→73, 59→48, 73→92, 8→59, 48→81. The nodes carry these weights: node 8: 3; node 26: 8; node 27: 10; node 48: 18; node 57: 4; node 59: 20; node 70: 17; node 73: 6; node 81: 2; node 84: 12; node 92: 10. 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. 61
  3. C. 110
  4. D. 44

Correct answer: A. 67

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