Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

这些数据我全部通过,可还是WA,大侠救救我。。。

Posted by tsmrdk at 2011-07-19 21:15:44 on Problem 3321
In Reply To:data Posted by:jerryjiang at 2011-06-27 03:23:09
#include<stdio.h>
#define N 100003
typedef struct Node
{
	int cnt;
	int lc,rc,p;
}Node;
Node Tree[N];
void inittree(int n)
{
	for(int i=0;i<=n;i++)
	{
		Tree[i].cnt=0;
		Tree[i].lc=Tree[i].rc=Tree[i].p=0;
	}
}
int buildtree(int i)
{
	if(i==0) return 0;
	Tree[i].cnt=buildtree(Tree[i].lc)+buildtree(Tree[i].rc)+1;
	return Tree[i].cnt;
}
void updatetree(int i,int d)
{
	while(i!=0)
	{
		Tree[i].cnt+=d;
		i=Tree[i].p;
	}	
}
int main()
{
	int n,i,u,v,tmp,m;
	char ch;
	scanf("%d",&n);
	inittree(n);
	for(i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		if(u>v) {tmp=u;u=v;v=tmp;}
		if(Tree[u].lc==0)
		{
			Tree[u].lc=v;			
			Tree[v].p=u;
		}
		else if(Tree[u].rc==0)
		{
			Tree[u].rc=v;		
			Tree[v].p=u;
		}
	}	
	buildtree(1);	
	scanf("%d",&m);
	while(m--)
	{
		scanf(" %c%d",&ch,&i);
		if(ch=='C')
		{
			if(Tree[i].cnt>Tree[Tree[i].lc].cnt+Tree[Tree[i].rc].cnt)
				updatetree(i,-1);
			else
				updatetree(i,1);
		}
		else if(ch=='Q')
		{
			printf("%d\n",Tree[i].cnt);
		}
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator