首页 > 其他 > 详细

hdu--2545--数据弱了?

时间:2014-08-18 18:27:52      阅读:229      评论:0      收藏:0      [点我收藏+]

我也不知道 为什么这题 那么水=-=

有人在discuss说数据弱了....

求这棵树上这个结点的深度就可以了

可能是数据比较大把 为什么我的运行时间那么长呢

  touch  me

写了2种 一个是慢慢搜上去 一个就直接depth[]数组记录

当然也可以depth father数组混合使用 这样就可以加上 路径压缩操作了

bubuko.com,布布扣
 1 #include <iostream>
 2 #include <cstring>
 3 using namespace std;
 4 
 5 const int size = 100010;
 6 int father[size];
 7 
 8 int find( int x , int ans )
 9 {
10     return father[x] == -1 ? ans : find( father[x] , ans+1 );
11 }
12 
13 int main()
14 {
15     cin.sync_with_stdio(false);
16     int n , m , x , y , xx , yy;
17     while( cin >> n >> m && (n||m) )
18     {
19         memset( father , -1 , sizeof(father) );
20         for( int i = 0 ; i<n-1 ; i++ )
21         {
22             cin >> x >> y;
23             father[y] = x;
24         }
25         while( m-- )
26         {
27             cin >> x >> y;
28             xx = find(x,0);
29             yy = find(y,0);
30             if( xx<=yy )
31                 cout << "lxh" << endl;
32             else
33                 cout << "pfz" << endl; 
34         }
35     }
36     return 0;
37 }
View Code

 

bubuko.com,布布扣
 1 #include <iostream>
 2 #include <cstring>
 3 using namespace std;
 4 
 5 const int size = 100010;
 6 int depth[size];
 7 
 8 int main()
 9 {
10     cin.sync_with_stdio(false);
11     int n , m , x , y;
12     while( cin >> n >> m &&(n||m) )
13     {
14         memset( depth , 0 , sizeof(depth) );
15         for( int i = 0 ; i<n-1 ; i++ )
16         {
17             cin >> x >> y;
18             depth[y] = depth[x] + 1;
19         }
20         while(m--)
21         {
22             cin >> x >> y;
23             if( depth[x]<=depth[y] )
24                 cout << "lxh" << endl;
25             else
26                 cout << "pfz" << endl;
27         }
28     }
29     return 0;
30 }
View Code

好像 这套 什么 uestc的难度不大=-=

 

hdu--2545--数据弱了?,布布扣,bubuko.com

hdu--2545--数据弱了?

原文:http://www.cnblogs.com/radical/p/3919992.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!