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,不明白为什么,谁能给个测试数据呀#include<iostream> #include<cstring> using namespace std; int N,M; struct fork { int parent,num,flag; }c[100100]; int main() { int i,j,x,y,lj; char q; cin>>N; for(i=1;i<=N;i++) { c[i].parent=0; c[i].num=1; c[i].flag=1; } for(i=0;i<N-1;i++) { cin>>x>>y; if(x>y) { int chang; chang=x;x=y;y=chang; } c[y].parent=x; lj=x; while(c[lj].parent) { c[lj].num+=c[y].num; lj=c[lj].parent; } c[1].num+=c[y].num; } cin>>M; for(i=0;i<M;i++) { cin>>q; cin>>j; if(q=='Q') cout<<c[j].num<<endl; else { if(c[j].flag==1) { c[j].flag=0; lj=j; while(c[lj].parent) { c[lj].num--; lj=c[lj].parent; } c[1].num--; } else { c[j].flag=1; lj=j; while(c[lj].parent) { c[lj].num++; lj=c[lj].parent; } c[1].num++; } } } return 0; } 感觉是建边是方向搞错了 Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator