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> #include <string.h> #define size 10010 int sets[size]; int flag[size]; int n; void make_set() { int i; for(i=1;i<=n;i++) sets[i]=i; } int find_set(int x) { int y=sets[x]; flag[x]=1; if(x==y) return y; else { y=find_set(y); sets[x]=y; return y; } } int result(int n) { if(flag[n]) return n; else return result(sets[n]); } int main() { int cases,i,father,son,x,y; scanf("%d",&cases); while(cases--) { scanf("%d",&n); make_set(); for(i=1;i<n;i++) { scanf("%d %d",&father,&son); sets[son]=father; } //for(i=1;i<=n;i++) //printf("%d\n",sets[i]); memset(flag,0,sizeof(flag)); scanf("%d %d",&x,&y); //printf("%d %d\n",x,y); find_set(x); //for(i=1;i<=n;i++) //printf("%d\n",sets[i]); printf("%d\n",result(y)); } return 1; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator