poj1703 种类并查集
来源:互联网 发布:澳洲工资算法 编辑:程序博客网 时间:2024/05/18 01:02
种类并查集,比poj1182水
#include <iostream>#include <cstring>using namespace std;const int N=100005;int father[N];int rank[N];int n,m;void init(){ memset(rank,0,sizeof(rank)); for (int i=0;i<=100000;i++) father[i]=i;}int find(int x){ if (x==father[x]) return x; int t=father[x]; father[x]=find(father[x]); rank[x]=(rank[x]+rank[t])%2; return father[x];}void Union(int a,int b){ int x=find(a); int y=find(b); if (x==y) return ; father[y]=x; rank[y]=(rank[a]+rank[b]+1)%2;}int main(){ int T; scanf("%d",&T); while (T--) { scanf("%d%d",&n,&m); init(); char d; int a,b; for (int i=1;i<=m;i++) { cin>>d; scanf("%d%d",&a,&b); if (d=='D') Union(a,b); if (d=='A') { if (find(a)==find(b)) { int x=rank[a]; int y=rank[b]; if (x==y) cout<<"In the same gang."<<endl; else cout<<"In different gangs."<<endl; } else cout<<"Not sure yet."<<endl; } } } return 0;}
0 0
- poj1703 种类并查集
- poj1703 种类并查集
- poj1703种类并查集
- poj1703(种类并查集)
- POJ1703 简单的种类并查集
- poj1703 Find them, Catch them 种类并查集
- POJ1703 Find Them,Catch Them 种类并查集
- Poj1703并查集
- poj1703 并查集
- poj1703 并查集
- poj1703(并查集)
- poj1703并查集
- poj1703 并查集
- poj1703 并查集
- POJ1703 并查集
- POJ1703 并查集
- POJ1703 POJ2492 并查集
- 种类为两种时,并查集的解题应用poj1703和hdu1829
- 把手教你玩转SOCKET模型之重叠I/O篇(下)
- 黑马程序员——内部类、匿名内部类
- zigbee__AF_DataRequest函数详解
- 致人生第一次面试--腾讯实习生面试
- ocos2d-x游戏实例之忍者飞镖——添加其他元素
- poj1703 种类并查集
- 主机pci设备直通
- hdu_1026
- s3c2440_MMU(1)
- MFC获取系统时间的方法
- 如何用Linux命令行管理网络:11个你必须知道的命令
- 分别用pfile 生成spfile 和用spfile 生成pfile;分别用这两个参数启动数据库。
- JavaEE的13种核心技术
- Oracle 归档与非归档的切换