CF 274 B. Zero Tree

树形dp,求连接到节点1的子树,在合法操作下 需要多少步能整棵树节点变为0;

#include
#include
#include
#include
#include
using namespace std;
const int maxn=100002;
typedef long long ll;
ll add[maxn],sub[maxn];
int n,val[maxn];
vectorEdge[maxn];
int dfs(int u,int fa)
{
	int i,j;
	add[u]=sub[u]=0;
	for(i=0;i0)sub[u]+=res;
	else add[u]-=res;
}
int main()
{
    //freopen("D://input.txt","r",stdin);  
	while(scanf("%d",&n)!=EOF)
	{
		int i,j,u,v;
		for(i=1;i<=n;i++)Edge[i].clear();
		for(i=1;i



你可能感兴趣的:(动态规划)