POJ 1703 Find them, Catch them(种类并查集)
来源:互联网 发布:看外汇行情的软件 编辑:程序博客网 时间:2024/06/05 20:25
题目地址:POJ 1703
种类并查集水题。
代码如下:
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;int bin[600000], rank[600000];int find1(int x){ int y; if(bin[x]!=x) { y=bin[x]; bin[x]=find1(bin[x]); rank[x]=rank[x]^rank[y]; } return bin[x];}int main(){ int t, n, m, i, a, b, f1, f2; char c; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(i=1;i<=n;i++) { bin[i]=i; rank[i]=0; } while(m--) { getchar(); scanf("%c%d%d",&c,&a,&b); f1=find1(a); f2=find1(b); if(c=='D') { if(f1!=f2) { bin[f2]=f1; rank[f2]=rank[a]^rank[b]^1; } } else { if(f1!=f2) { printf("Not sure yet.\n"); } else { if(rank[a]!=rank[b]) puts("In different gangs."); else puts("In the same gang."); } } } } return 0;}
2 0
- 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(种类并查集)
- Find them, Catch them - POJ 1703 种类并查集
- POJ 1703 Find them, Catch them 种类并查集
- POJ 1703 - Find them, Catch them(种类并查集)
- POJ 1703 Find them, Catch them 种类并查集
- POJ Find them, Catch them (种类并查集)
- poj 1703 Find them, Catch them 带权并查集OR种类并查集
- 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(种类并查集)
- CSS快速制作图片轮播的焦点
- 【模拟】【HDU1443】 Joseph
- Linux hostname主机名配置文件与文件 /etc/hosts解说
- AIDL 服务的由来 及 使用方法
- 直接插入排序的四种实现方法
- POJ 1703 Find them, Catch them(种类并查集)
- 黑马程序员_JAVA其他常用对象
- vmware workstation 10 installation on centos 7 (kernel 3.10, 3.13, etc)
- HDU 3622 2-sat模板
- C++有哪几种情况只能用初始化列表,而不能用赋值?
- 文件操作
- 做游戏?
- 让APP快速适配iPhone6及Plus的诀窍
- CF 21C Stripe 2