标签:des style blog http color io os ar 使用
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2545
Time Limit: 10000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 564 Accepted Submission(s):
305
1 #include <iostream> 2 #include <cstdio> 3 4 using namespace std; 5 int father[100010],n,m; 6 7 int find(int a) 8 { 9 int flag=0; 10 while(a!=father[a]) 11 { 12 a=father[a]; 13 flag++; 14 } 15 return flag; 16 } 17 18 int main () 19 { 20 while (~scanf("%d%d",&n,&m)) 21 { 22 for (int i=1; i<=n; i++) 23 father[i]=i; 24 if (n==0&&m==0) 25 break; 26 for (int i=1; i<=n-1; i++) 27 { 28 int a,b; 29 scanf("%d%d",&a,&b); 30 father[b]=a; 31 } 32 for (int i=1; i<=m; i++) 33 { 34 int startl,startp; 35 scanf("%d%d",&startl,&startp); 36 int t1=find(startl); 37 int t2=find(startp); 38 if (t1>t2) 39 printf ("pfz\n"); 40 else 41 printf ("lxh\n"); 42 } 43 } 44 return 0; 45 }
标签:des style blog http color io os ar 使用
原文地址:http://www.cnblogs.com/qq-star/p/4035486.html