poj1703种类并查集
来源:互联网 发布:淘宝哪里有卖微信号的 编辑:程序博客网 时间:2024/05/20 06:04
题目大意:
在这个城市里有两个黑帮团伙,现在给出N个人,问任意两个人他们是否在同一个团伙
输入D x y代表x于y不在一个团伙里
输入A x y问x与y是否在同一团伙
输入t组,n人,m条语句
N (N <= 10^5)
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;int par[100005*2];int F(int x){ int i=x; while(x!=par[x]) x=par[x]; par[i]=x; return x;}void join(int x,int y){ int xx=F(x); int yy=F(y); par[xx]=yy;}int main(){ int n,m,i,t,a,b; char c; cin>>t; while(t--) { cin>>n>>m; for(i=1; i<=n*2; i++) par[i]=i; while(m--) { cin>>c; scanf("%d%d",&a,&b); if(c=='A') { if(F(a)==F(b)) puts("In the same gang."); else if(F(a+n)==F(b)) puts("In different gangs."); else puts("Not sure yet."); } else { join(a,b+n); join(a+n,b); } } } return 0;}
阅读全文
0 0
- poj1703 种类并查集
- poj1703 种类并查集
- poj1703种类并查集
- poj1703(种类并查集)
- POJ1703 简单的种类并查集
- poj1703 Find them, Catch them 种类并查集
- POJ1703 Find Them,Catch Them 种类并查集
- Poj1703并查集
- poj1703 并查集
- poj1703 并查集
- poj1703(并查集)
- poj1703并查集
- poj1703 并查集
- poj1703 并查集
- POJ1703 并查集
- POJ1703 并查集
- POJ1703 POJ2492 并查集
- 种类为两种时,并查集的解题应用poj1703和hdu1829
- 欢迎使用CSDN-markdown编辑器
- js中的new操作符与Object.create()的作用与区别
- 第四章 正则表达式回溯法原理
- @Resource与@Autowired的区别
- java实现选择排序
- poj1703种类并查集
- 静态方法和静态属性的最佳实践(单例模式)
- 雄关漫道真如铁,而今迈步从头越(嗨翻C语言)8.6
- 在WorldMain中调试OgreMain的配置说明
- Gson解析JSON数据中动态未知字段key的方法
- 第五章 正则表达式的拆分
- [HDU
- 拆分你的React组件
- Axure8.0如何汉化?