POJ 1703 Find them, Catch them .
来源:互联网 发布:网络宣传方案 编辑:程序博客网 时间:2024/06/01 09:58
题目地址
#include<iostream>#include<cstdio>#include<queue>#include<map> #include<vector>#include<cctype>#include<cstring>#include<algorithm>using namespace std;const int maxn=100000+5;int p[maxn],r[maxn];int getParent(int x){if(p[x]==x) return x;int xp=getParent(p[x]);r[x]=(r[x]+r[p[x]])%2;return p[x]=xp;}void merge(int xp,int yp,int x,int y){p[xp]=yp;r[xp]=(r[x]+r[y]+1)%2;}int main(){int n,m,kase=0;int T;cin>>T;while(T--){cin>>n>>m;for(int i=1;i<=n;i++) p[i]=i,r[i]=0;int x,y,xp,yp;char cmd; while(m--){cin>>cmd>>x>>y;xp=getParent(x);yp=getParent(y);if(cmd=='D'){if(xp!=yp) merge(xp,yp,x,y);}else {if(xp==yp&&r[x]==r[y]) cout<<"In the same gang.";else if(xp==yp&&r[x]!=r[y]) cout<<"In different gangs.";else cout<<"Not sure yet.";cout<<endl;}}}return 0;}
0 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
- 关于JAVA环境变量的配置问题
- HDU 5750
- 串行通信总述
- poj2403 模拟题目
- CodeForces 547B - Mike and Feet(单调栈)
- POJ 1703 Find them, Catch them .
- pandas append性能问题
- Bonita BPM Study
- java异常分类
- 内部类
- Reading Books
- csdn待改进点之34------>为什么会又在乱跳转? 请不要说重现不了!
- 在eclipse中使用CDT插件导入外部静态库
- 二分查找