poj-1703
来源:互联网 发布:sql删除数据库表数据 编辑:程序博客网 时间:2024/05/16 07:25
并查集:种类并查集:
分为1~N,N~2N两类;
a,b第一次出现时是p[a]=a,p[b]=b;
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>using namespace std;int p[200010];int findd(int x){ if (p[x] < 0 ) return x; else return p[x] = findd(p[x]);}int main (){ int t; scanf ("%d",&t); while (t--) { int n,m; char b[5]; int c,d; scanf ("%d%d",&n,&m); memset(p,-1,sizeof(p)); for (int i=1;i<=m;i++) { scanf ("%s",b); scanf ("%d %d",&c,&d); if (!strcmp(b,"A")) { if (n==2) printf("In different gangs.\n"); else if (findd(c) != findd(d) && findd(c)!=findd(d+n)) printf("Not sure yet.\n"); else if (findd (c) == findd(d)) printf("In the same gang.\n"); else printf("In different gangs.\n"); } else { if (findd (c)!= findd (d+n)) { p[findd (c)] = findd (d+n); p[findd (d)] = findd (c+n); } } } } return 0;}
0 0
- poj 2492 && poj 1703
- poj 1703
- POJ 1703
- poj 1703
- POJ 1703
- poj 1703
- poj 1703
- POJ 1703
- POJ 1703
- poj-1703
- poj-1703
- poj 1703
- POJ 1703
- poj 1703
- POJ 1703
- poj 1703
- POJ 1703
- poj 1703
- Cocos2d-x开发---关于安卓打包所遇到的错误记录
- 数据结构与算法MOOC / 第2周 线性表(Linear Lists) 2:多项式加法
- Tomcat Host组件
- java的基本数据类型
- 第八周项目3.1分段函数求值
- poj-1703
- LeetCode || Minimum Path Sum
- 数据结构与算法MOOC / 第2周 线性表(Linear Lists3:大整数乘法
- [ACM] FZU 2087 统计数边 (有多少边至少存在一个最小生成树里面)
- 数据挖掘领域的顶级会议和期刊
- LVS 学习
- 第八周项目 判断(1)
- [Android]判断网络连接是否可用
- UML类图集中关系的总结