博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu--2545--数据弱了?
阅读量:4634 次
发布时间:2019-06-09

本文共 1740 字,大约阅读时间需要 5 分钟。

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

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

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

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

  

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

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

1 #include 
2 #include
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
> 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 else33 cout << "pfz" << endl; 34 }35 }36 return 0;37 }
View Code

 

1 #include 
2 #include
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
> 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 else26 cout << "pfz" << endl;27 }28 }29 return 0;30 }
View Code

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

 

转载于:https://www.cnblogs.com/radical/p/3919992.html

你可能感兴趣的文章
Jquery 多行拖拽图片排序 jq优化
查看>>
文件分割机
查看>>
shell的交互式和非交互式登录
查看>>
【转载】ASP.NET自定义404和500错误页面
查看>>
定长顺序串的实现
查看>>
使用var声明的变量 和 直接赋值并未声明的变量的区别
查看>>
[读书笔记]TCP/IP详解V1读书笔记-3
查看>>
Just a Hook HDU - 1698
查看>>
Polo the Penguin and Matrix
查看>>
简评知乎的优点与不足
查看>>
20分钟快速了解Redis
查看>>
[AHOI2009]最小割(最大流+tarjan)
查看>>
Nginx 动静分离
查看>>
Apache - Storm
查看>>
tkinter中scale拖拉改变值控件(十一)
查看>>
NB-IOT连接移动onenet平台流程
查看>>
无敌简单快速的文件服务器sgfs
查看>>
Chapter 5 Blood Type——33
查看>>
从github clone文件: Failed to receive SOCKS4 connect request ack.
查看>>
英语学习Day1
查看>>