并查集 示例 : poj 1703 [Find them, Catch them - 帮派之争]
来源:互联网 发布:p2p网络应用ppt 编辑:程序博客网 时间:2024/05/21 18:38
#include <iostream>#include <string>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>#include <vector>#include <stack>#include <deque>#include <queue>#include <bitset>#include <list>#include <map>#include <set>#include <iterator>#include <algorithm>#include <functional>#include <utility>#include <sstream>#include <climits>#include <cassert>#define MID(x,y) ( ( x + y ) >> 1 )#define L(x) ( x << 1 )#define R(x) ( x << 1 | 1 )#define BUG puts("here!!!");#define STOP system("pause");using namespace std;const int N = 100005;int f[N+N];int n, m;int find(int x) {if(f[x] < 0) return x;return f[x] = find(f[x]);}int main() {int loop;cin >> loop;while(loop--) {scanf("%d%d", &n, &m);memset(f, 255, sizeof(f));while(m--) {int a, b;char s[3];scanf("%s%d%d", s, &a, &b);if(s[0] == 'A') {if(find(a) != find(b) && find(a) != find(b+n)) {printf("Not sure yet.\n");}else if(find(a) == find(b)) {printf("In the same gang.\n");}else printf("In different gangs.\n");}else {if(find(a) != find(b+n)) {f[find(a)] = find(b+n);f[find(b)] = find(a+n);}}}}return 0;}Sample Input
1
5 5
A 1 2
D 1 2
A 1 2
D 2 4
A 1 4
Sample Output
Not sure yet.
In different gangs.
In the same gang.
- 并查集 示例 : 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 (关系并查集)
- boolean isMultipart=ServletFileUpload.isMultipartContent(request);
- 如何减少 innodb 数据库关闭的时间?
- 一月一首乐之灵动--不再让你孤单(陈升)
- 生活随笔:随想
- Ubuntu下mentohust的配置
- 并查集 示例 : poj 1703 [Find them, Catch them - 帮派之争]
- java web 第二天笔记
- Can’t connect to MySQL server有关linux tcp连接优化
- Trie 字典树 poj 2001 示例
- WEbService服务端-用Axis客户端测试遇到的问题Exception in thread "main" AxisFault
- Proxifier PE v3.21
- Caused by: java.io.FileNotFoundException: C:\apache-tomcat-6.0.35\webapps\day20\WEB-INF\upload\2\9\a
- js省市二级联动 无数据库
- 关于数据库连接的问题