poj 1703 种类并查集
2014-09-28 17:05
435 查看
切点
#include <stdio.h> #include <string.h> #include <stdlib.h> int n,m; char ts[10]; int parent[200020]; int root(int p){ if(parent[p]==-1) return p; else return parent[p]=root(parent[p]); } void merge(int a,int b){ a=root(a); b=root(b); parent[a]=b; } int main() { int T; scanf("%d",&T); while(T--) { int i,j; int ta,tb; memset(parent,-1,sizeof(parent)); scanf("%d%d",&n,&m); while(m--) { scanf("%s%d%d",ts,&ta,&tb); if(ts[0]=='D') { if(root(ta*2)!=root(tb*2+1)) merge(ta*2,tb*2+1); if(root(ta*2+1)!=root(tb*2)) merge(ta*2+1,tb*2); } else { if(root(ta*2)==root(tb*2)) printf("In the same gang.\n"); else if(root(ta*2)==root(tb*2+1)) printf("In different gangs.\n"); else printf("Not sure yet.\n"); } } } }
相关文章推荐
- POJ 1703 Find them, Catch them(种类并查集)
- POJ 1703 Find them, Catch them(种类并查集)
- poj 1703 种类并查集
- 种类并查集·POJ-1703
- POJ1703 简单的种类并查集
- poj 1703 Find them, Catch them 带权并查集OR种类并查集
- poj1703 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(1703),种类并查集
- poj1703种类并查集
- poj 1703 Find them, Catch them(种类并查集)
- POJ1703--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 种类并查集