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 |
大哥大姐们帮小弟查下错!#include <stdio.h> int p[30006]; int s[30006]; int findp(int x) { if(p[x]!=x) p[x]=findp(p[x]); return p[x]; } int finds(int x) { if(s[x]!=x) s[x]=finds(s[x]); return s[x]; } void markset() { int i; for(i=1;i<=30000;i++) { p[i]=i; s[i]=i; } } int main() { int n; int i; int tmp,tmp1,tmp2; int cnt; int son,fath; char op[3]; while(scanf("%d",&n)!=EOF) { markset(); for(i=1;i<=n;i++) { scanf("%s",op); if(op[0]=='M') { scanf("%d%d",&son,&fath); tmp1=findp(son); tmp2=finds(fath); p[tmp1]=tmp2; s[tmp2]=tmp1; } else if(op[0]=='C') { cnt=0; scanf("%d",&tmp); while(p[tmp]!=tmp) { tmp=p[tmp]; cnt++; } printf("%d\n",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