HDU 1520 - Anniversary Party

Problem : Given a tree, to choose some vertices, s.t. the neighbour in the tree cannot be chosen at the same time. Each vertice has a value a[i], find the maximum sum of the chosen value.
Solution : Denote f[i][0] to be the maximum value of sub-tree rooted at i, and i is not chosen. f[i][1] to be the maximum value of sub-tree rooted at i, and i is chosen. Then f[i][0]=sum(max(f[j][0], f[j][1])), where j is all the children of i. f[i][1]=sum(f[j][0]), where j is all the children of i.