poj 1703 Find them, Catch them
来源:互联网 发布:如何提高淘宝卖家信誉 编辑:程序博客网 时间:2024/06/01 09:25
还是种类并查集!!
题目链接:
点击打开链接
题目大意:
给出不属于同一集合的人的关系。给出询问并判断是不是同一个组织或者当前信息不能判断
其关系。
#include<cstdio>#include<iostream>using namespace std;int fa[100010];int re[100010];void init(int n){ for(int i=1;i<=n;i++) { fa[i]=i; re[i]=0; }}int find(int x){ if(fa[x]!=x) { int t=fa[x]; fa[x]=find(fa[x]); re[x]=(re[x]+re[t])%2; } return fa[x];}void Union(int x,int y){ int fx=find(x); int fy=find(y); fa[fx]=fy; re[fx]=(re[y]+2-re[x]+1)%2;}int main(){ int T,n,m,x,y; char u; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); init(n); getchar(); for(int i=0;i<m;i++) { scanf("%c%d%d",&u,&x,&y); if(u=='D') { Union(x,y); } else { int fx=find(x); int fy=find(y); if(fx!=fy) printf("Not sure yet.\n"); else { if((re[x]+re[y])%2) printf("In different gangs.\n"); else printf("In the same gang.\n"); } } getchar(); } } return 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
- 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
- void *类型的变量
- struts2拦截器的原理使用方法
- 易經大意(11) 三和 韓長庚 著
- 利用ArrayList对Hashtable其进行排序
- SGU114-Telecasting station
- poj 1703 Find them, Catch them
- MES 趣谈
- Android 设置 Setting --->开发者选项 中选项为默认配置(by liukun321咕唧咕唧)
- centos5.4安装g++和gcc
- Raspberry Pi 安装Sensor驱动
- 高性能MySql进化论(九):查询优化器常用的优化方式
- iOS7应用开发9:autolayout自动布局
- crack the code interview 2.5
- IP与MAC为什么同是存在?