B - 电影节
2022/5/5 23:18:52
本文主要是介绍B - 电影节,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
题目链接 https://acm.sdut.edu.cn/onlinejudge3/contests/3989/problems/B
并查集模板
唯一值得做的地方是循环输入(一开始真的忘记了)
放AC代码
1 #include<bits/stdc++.h> 2 using namespace std; 3 int n,m,a,b,c,d; 4 int p[100010]; 5 6 void init(int n) 7 { 8 for(int o=1; o<=n; o++) 9 p[o]=o; 10 } 11 12 int getp(int o) 13 { 14 return p[o]==o?o:(p[o]=getp(p[o])); 15 } 16 17 void Union(int x,int y) 18 { 19 int x_root=getp(x); 20 int y_root=getp(y); 21 if(x_root!=y_root) 22 p[y_root]=x_root; 23 return; 24 } 25 26 int main() 27 { 28 while(cin>>n>>m) 29 { 30 init(n); 31 for(int i=1; i<=m; i++) 32 { 33 cin>>a>>b; 34 Union(a,b); 35 } 36 cin>>c>>d; 37 if(getp(c)==getp(d)) cout<<"same"<<endl; 38 else cout<<"not sure"<<endl; 39 } 40 return 0; 41 }
这篇关于B - 电影节的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?