(用树结构支持并查集8.2.2)POJ 1703 Find them, Catch them(并查集的简单使用: 判断两个元素是否属于同一集合)
来源:互联网 发布:linux安装软件 编辑:程序博客网 时间:2024/06/06 13:23
/* * POJ_1703.cpp * * Created on: 2013年11月5日 * Author: Administrator */#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxn = 100000;int set[maxn*2+10];int set_find(int p){//并查集的查找过程if(set[p] < 0){return p;}return set[p] = set_find(set[p]);}int main(){int t;scanf("%d",&t);while(t--){memset(set,-1,sizeof(set));//开始时,每个罪犯都是一个集合int n,m;scanf("%d%d",&n,&m);char str[15];int a,b;int i;for(i = 0 ; i < m ; ++i){scanf("%s %d %d",str,&a,&b);if(str[0] =='A'){//如果a与b不是同一帮派&&a与b的另一个帮派也不是同一个帮派if(set_find(a) != set_find(b) && set_find(a) != set_find(b+n)){printf("Not sure yet.\n");}else if(set_find(a) == set_find(b)){//如果a与b属于同一个帮派printf("In the same gang.\n");}else{printf("In different gangs.\n");}}else{if(set_find(a) != set_find(b+n)){set[set_find(a)] = set_find(b+n);//将a的帮派设为b的另外一个帮派set[set_find(b)] = set_find(a+n);}}}}return 0;}
- (用树结构支持并查集8.2.2)POJ 1703 Find them, Catch them(并查集的简单使用: 判断两个元素是否属于同一集合)
- POJ 1703 Find them, Catch them【典型并查集:判断在不同的集合】
- (POJ 1703) Find them, Catch them【典型并查集:判断在不同的集合】
- POJ 1703 Find them, Catch them(并查集)
- POJ 1703 Find them, Catch them //并查集
- poj 1703 Find them, Catch them 并查集
- poj 1703 Find them, Catch them(并查集)
- poj 1703 Find them, Catch them //并查集
- POJ 1703 Find them, Catch them 并查集
- poj 1703 Find them, Catch them (并查集)
- poj 1703 Find them, Catch them(种类并查集)
- poj 1703 Find them, Catch them(种类并查集)
- poj 1703 -- Find them, Catch them(并查集)
- poj 1703 Find them, Catch them(并查集应用)
- POJ 1703 Find them, Catch them (并查集)
- poj 1703 - Find them, Catch them(并查集)
- poj 1703 Find them, Catch them(关系并查集)
- POJ 1703 Find them, Catch them 种类并查集
- Android利用SparseArray替换使用HashMap<Integer,E>
- CSS中的position:relative;的作用
- CentOS源码安装 apache2.2.5
- android 图片点击变暗的另一种办法
- 访问网站提示“应用程序脱机”
- (用树结构支持并查集8.2.2)POJ 1703 Find them, Catch them(并查集的简单使用: 判断两个元素是否属于同一集合)
- IOS--启动其他应用程序
- tomcat 调优
- 不是技术牛人,如何拿到国内IT巨头的Offer
- 更新git上fork来代码的方法
- 美国官网入手T-Mobile contract-free后续
- 可以处理负权的单源最短路径的SPFA算法带图详解(自己画的图)
- OCP-1Z0-052-V8.02-40题
- PHP 流程控制 判断 循环语句