poj-1703 Find them, Catch them---带权值的并查集
来源:互联网 发布:青年人休闲鞋推荐 知乎 编辑:程序博客网 时间:2024/05/18 04:49
。。。
和 poj 1182 食物链 差不多。。
http://blog.csdn.net/u010489389/article/details/9321583
#include<stdio.h>#include<string.h>int n,m;int f[100010];int d[100010];int root(int p){if(f[p]==-1) return p;else{int fa=f[p];f[p]=root(f[p]);d[p]=(d[p]+d[fa])%2;return f[p];}}void merge(int a,int b){int aa=root(a);int bb=root(b);f[aa]=bb;d[aa]=(d[b]-d[a]+1)%2;}int main(){int t;scanf("%d",&t);int i,j,k;int a,b;char ch[5];while(t--){scanf("%d%d",&n,&m);memset(f,-1,sizeof(f));memset(d,0,sizeof(d));while(m--){scanf("%s%d%d",ch,&a,&b);if(ch[0]=='A'){if(root(a)!=root(b))printf("Not sure yet.\n");else{if(d[a]==d[b])printf("In the same gang.\n");elseprintf("In different gangs.\n");}}else{if(root(a)!=root(b))merge(a,b);}}}}
- 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 并查集
- Who's in the Middle 堆排序,poj 2388
- 百钱买百鸡
- Simple Admob android for unity3d [在Android中添加广告]
- Android异常处理之android.content.res.Resources$NotFoundException
- 巧用js灵活提交表单,解决一个页面有多个提交按钮
- poj-1703 Find them, Catch them---带权值的并查集
- 快速备份,还原数据库。
- 机房收费系统(二)报表的设计Grid 的使用
- (计算几何step8.1.2.2)POJ 1269 Intersecting Lines(使用叉积来计算两条直线的交点)
- Java实现水仙花数
- 黑马程序员_银行业务调度系统
- Java transient关键字使用小记
- 【MoreWindows工作笔记4】 获取文件图标,类型名称,属性 SHGetFileInfo
- 在WAS控制台,环境下添加新的虚拟主机别名