Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
这些数据我全部通过,可还是WA,大侠救救我。。。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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator