链接
题目描述
给出一棵有根树,要求选出一些结点。若选中某个结点,则它本身、它的父亲结点和儿子结点被覆盖。选出第i个结点需要一定的花费ki ,求覆盖这棵树所需的最小花费。
样例输入
6
1 30 3 2 3 4
2 16 2 5 6
3 5 0
4 4 0
5 11 0
6 5 0
样例输出
25
思路
从深度深的地方往深度浅的地方搞
对于一个点x,我们分别处理它由父亲,儿子,自己标记的情况
f x , 0 + = m i n ( f s o n , 1 , f s o n , 2 ) f_{x,0} += min(f_{son,1},f_{son,2}) fx,0+=min(fson,1,fson,2)
f x , 1 + = m i n ( f s o n , 1 , f s o n , 2 ) + m i n ( f s o n , 2 − m i n ( f s o n , 1 , f s o n , 2 ) ) f_{x,1} += min(f_{son,1},f_{son,2}) + min(f_{son,2}-min(f_{son,1},f_{son