hdu--2545--数据弱了?

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

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

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

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

  touch  me

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

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

 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 }

 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 }

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

hdu--2545--数据弱了?

时间: 2024-08-05 02:29:03

hdu--2545--数据弱了?的相关文章

hdu 2016 数据的交换输出

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2016 题目大意:把最小的和第一个交换并输出.注意格式哦! 1 #include <stdio.h> 2 int main () 3 { 4 int n,a[110],i,j,t,min; 5 while (scanf("%d",&n)!=EOF) 6 { 7 if (n==0) 8 break; 9 for (i=0; i<n; i++) 10 { 11 scan

hdu 2545 树上战争(并查集)

题目链接: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 Problem Description 给一棵树,如果树上的某个节点被某个人占据,则它的所有儿子都被占据,

百度之星2017 HDU 6109 数据分割 并查集+set

数据分割 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6109 Description 小w来到百度之星的赛场上,准备开始实现一个程序自动分析系统.这个程序接受一些形如xi=xj 或 xi≠xj 的相等/不等约束条件作为输入,判定是否可以通过给每个 w 赋适当的值,来满足这些条件.输入包含多组数据.然而粗心的小w不幸地把每组数据之间的分隔符删掉了.他只知道每组数据都是不可满足的,且若把每组数据的最后一个约束条件去掉,则该组数据是可满足的.请帮助他

HDU 6109 数据分割 【并查集】 (2017&quot;百度之星&quot;程序设计大赛 - 初赛(A))

数据分割 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1119    Accepted Submission(s): 268 Problem Description 小w来到百度之星的赛场上,准备开始实现一个程序自动分析系统. 这个程序接受一些形如xi=xj 或 xi≠xj 的相等/不等约束条件作为输入,判定是否可以通过给每个 w 赋

hdu 2016 数据的交换输出 (java)

问题: 这是一个比较简单的题目,叫第一遍时,审题不准确给它排序了,按照其要求只需取得最小值的下标与第一个交换就AC了. 数据的交换输出 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 67406    Accepted Submission(s): 25632 Problem Description 输入n(n<100)个数,找出其中最

HDU 5139数据离线处理

此题可以找到规律f(n) = 1! * 2! *...*n!, 如果直接打表的话,由于n比较大(10000000),所以会超内存,这时候就要用到离线处理数据,就是先把数据存起来,到最后在暴力一遍求解就行了,代码如下 代码一(超内存): 1 #include <stdio.h> 2 3 const long long mod = 1000000007; 4 const int N = 10000007; 5 long long a[N]; 6 7 int main() 8 { 9 a[0] =

hdu 2545 并查集

题目描述:给定一个无向图,判断这个图是否满足任意两点之间有且只有一条通路. 思路:并查集,若a和b之间有一条边且处于不同的集合中,则将a和b所在集合合并:若a和b本就在同一集合中,则a到b一定有不止一条通路.另外还需要判断一下 是否所有的点最后都在一个集合中,即根的数量是否等于1. 注意:0 0的情况应该输出Yes 1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 using namespa

hdu 2545 求当前结点到根节点的距离

求当前结点到根节点的距离 Sample Input 2 1 //n m 1 2 1 2 //询问 5 2 1 2 1 3 3 4 3 5 4 2 //询问 4 5 0 0 Sample Output lxh pfz lxh 1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <algorithm> 5 # include <cmath> 6 #

本来dp 但是数据弱 枚举可过

1 program hehe; 2 var 3 ans,n,r,i,j,k,x,y:longint; 4 c:array[-10..5000,-10..5000] of longint; 5 begin 6 readln(n,r); 7 for i:=1 to n do 8 begin 9 read(x,y); 10 read(c[x,y]); 11 end; 12 for i:=0 to 5000 do 13 for j:=0 to 5000 do 14 c[i,j]:=c[i,j]+c[i-

HDU 1032.The 3n + 1 problem【注意细节】【估计数据不强】【8月21】

The 3n + 1 problem Problem Description Problems in Computer Science are often classified as belonging to a certain class of problems (e.g., NP, Unsolvable, Recursive). In this problem you will be analyzing a property of an algorithm whose classificat