poj1703find them,catch them
来源:互联网 发布:辐射3 mac 编辑:程序博客网 时间:2024/05/31 00:39
#include<stdio.h>#include<iostream>using namespace std;long set[505000];long rank[505000];long findset(long x){ long y=x; if(set[x]==x) return x; y=findset(set[x]); rank[x]=(rank[set[x]]+rank[x])%2; set[x]=y; return y;}void unions(long x,long y){ long a,b; a=findset(x); b=findset(y); set[b]=a; rank[b]=(rank[x]+rank[y]+1)%2;}int main(){ long t,n,m,x,y,a,b; char c; scanf("%d",&t); for(long i=0;i<t;i++){ //scanf("%d %d\n",&n,&m); scanf("%d %d",&n,&m); for(long j=1;j<=n;j++){ set[j]=j; rank[j]=0; } for(long j=0;j<m;j++){ //scanf("%c %d %d\n",&c,&x,&y); getchar(); scanf("%c %d %d",&c,&x,&y); a=findset(x); b=findset(y); //cout<<a<<" "<<b<<" "<<rank[x]<<" "<<rank[y]<<endl; if(c=='D') unions(x,y); else if(c=='A'){ if(a!=b) {cout<<"Not sure yet."<<endl; continue;} if(a==b){ if(rank[x]==rank[y]) {cout<<"In the same gang."<<endl; continue;} else {cout<<"In different gangs."<<endl; continue;} } } } } return 0;}
好吧。。。我只是为了刷并查集,看题的时候莫名的觉得这题很熟悉。。。结果居然是做过的。。。难道我刷错了,blog里又米题解诶。。。
- poj1703find them,catch them
- poj1703Find them, Catch them
- poj1703find them,catch them
- poj1703Find them catch them
- 并查集(种类并查集)POJ1703Find them, Catch them解题报告
- Find them, Catch them
- BIT1062Find them, Catch them
- Find them, Catch them
- Find them, Catch them
- Find them, Catch them
- Find them, Catch them
- Find them, Catch them
- Find them, Catch them
- Find them, Catch them
- Find them, Catch them
- Find them, Catch them
- Find them, Catch them
- Find them, Catch them
- 成功靠的是先知、远见、策略、实现…
- 惠通C语言面试
- C++ Boost Thread 编程指南
- C++网络开发包ACE环境的配置与调试
- poj1611The Suspects
- poj1703find them,catch them
- Open4Cms用户权限管理设计
- 如何在Windows 7 中创建触发器开始 Windows 服务
- 2011-11~17 新闻采集
- error C2664: “CWnd::MessageBoxW”: 不能将参数 1 从“const char [17]”转换为“LPCTSTR”
- 正则表达式 对ip地址排序(用到了分割和替换)
- OK
- 图片热点区域的简单应用
- 我的经验分享--FileNet流程设计概述