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 |
why wa?why wa?#include<stdio.h> long i,p,x,y; struct dd{ long d,sum,top; }a[30100]; long findroot(long xq){ long it,kt,i1,jt; kt=0; it=xq; while(a[it].top!=it){ kt+=a[it].d; it=a[it].top; }; i1=it; it=xq; while(a[it].top!=it){ jt=a[it].top; a[it].top=i1; a[jt].d=kt-a[it].d; a[it].d=kt; kt=a[jt].d; it=jt; } return i1; } void uni(long xt,long yt){ long iq,jq; iq=findroot(xt); jq=findroot(yt); a[jq].top=iq; a[jq].d=a[iq].sum; a[iq].sum+=a[jq].sum; } int main(){ char op; scanf("%ld",&p); for (i=0;i<30004;i++){ a[i].d=0; a[i].sum=1; a[i].top=i; } while(p--){ scanf("\n%c",&op); switch(op){ case 'M': scanf("%ld%ld",&x,&y); uni(x,y); break; case 'C': scanf("%ld",&x); printf("%ld\n",a[findroot(x)].sum-a[x].d-1); break; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator