POJ 1703 Find them, Catch them
简单带权并查集0,1关系
//#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<iostream> #include<sstream> #include<cmath> #include<climits> #include<string> #include<map> #include<queue> #include<vector> #include<stack> #include<set> using namespace std; typedef long long ll; typedef pair<int,int> pii; #define pb(a) push_back(a) #define INF 0x1f1f1f1f #define lson idx<<1,l,mid #define rson idx<<1|1,mid+1,r #define PI 3.1415926535898 template<class T> T min(const T& a,const T& b,const T& c) {return min(min(a,b),min(a,c)); } template<class T> T max(const T& a,const T& b,const T& c) {return max(max(a,b),max(a,c)); } void debug() { #ifdef ONLINE_JUDGE #elsefreopen("d:\\in.txt","r",stdin);freopen("d:\\out1.txt","w",stdout); #endif } int getch() {int ch;while((ch=getchar())!=EOF) {if(ch!=' '&&ch!=' ')return ch;}return EOF; } int da[110000],rel[110000]; int find(int a) {if(a==da[a])return a;int root=find(da[a]);rel[a]=(rel[a]+rel[da[a]])%2;return da[a]=root; } int main() {int t;scanf("%d",&t);for(int ca=1;ca<=t;ca++){int n,q;scanf("%d%d",&n,&q);for(int i=1;i<=n;i++){da[i]=i;rel[i]=0;}for(int Q=1;Q<=q;Q++){char op[10];int a,b;scanf("%s%d%d",op,&a,&b);int fa=find(a),fb=find(b);if(op[0]=='A'){if(fa!=fb)printf("Not sure yet.\n");else printf("%s\n",(rel[a]-rel[b]+2)%2?"In different gangs.":"In the same gang.");}else{if(fa!=fb){da[fb]=fa;rel[fb]=(rel[a]-rel[b]+1)%2;}}}}return 0; }
View Code
转载于:https://www.cnblogs.com/BMan/p/3274849.html
POJ 1703 Find them, Catch them相关推荐
- POJ 1703 Find them, Catch them(并查集高级应用)
POJ 1703 Find them, Catch them(并查集高级应用) 手动博客搬家:本文发表于20170805 21:25:49, 原地址https://blog.csdn.net/sunc ...
- POJ 1703 Find them, Catch them(路径压缩并查集)
POJ 1703 Find them, Catch them(路径压缩并查集) 2014年03月11日 20:13:54 阅读数:881 POJ 1703 Find them, Catch them( ...
- POJ 1703 Find them, Catch them 并查集
题意:给你t组数据,每组数据给你编号为1-n的坏人,这些坏人要么属于团伙A,要么属于团伙B,然后给你m次操作: A操作:询问x和y是不是同一个团伙 D操作:告诉你x和y不是同一个团伙 思路:和POJ ...
- POJ 1703 Find them, Catch them【并查集】
题意: 有 N 个人分属于两个帮派,对应两种操作: A X Y 询问x,y 是否属于一个帮派,或两者关系不能确定. D X Y X和Y 分属不同帮派 分析: 感觉就是简化版 ...
- POJ 1703 Find them, Catch them 种类并查集
题意 给出一堆点和关系 D为两点不同集合 A为查询两点是否不同集合 n<=1e5 code #include<cstdio> #include<iostream> #in ...
- c语言编辑87152,POJ 3287 (基础BFS) Catch That Cow
这是做的第一道BFS,很基础很简单的题目 广度优先搜索算法如下:(用QUEUE) (1) 把初始节点S0放入Open表中: (2) 如果Open表为空,则问题无解,失败 退出: (3) 把Open表的 ...
- (并查集 带关系)Find them, Catch them -- poj -- 1703
链接: http://poj.org/problem?id=1703 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3676 ...
- 【POJ - 1703】Find them, Catch them(带权并查集之--种类并查集 权为与父节点关系)
题干: Find them, Catch them Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 36176 Accep ...
- Find them, Catch them POJ - 1703(种类并查集)
题意: 在这个城市里有两个黑帮团伙,现在给出N个人,问任意两个人他们是否在同一个团伙 1.输入D x y代表x于y不在一个团伙里 2.输入A x y要输出x与y是否在同一团伙或者不确定他们在同一个团伙 ...
最新文章
- 微生物组科学蓬勃发展,5大方向备受行业关注!
- Learun FrameWork 强大工作流引擎,让OA更智能
- Dialog外部点击事件
- 转赋值表达式解析的流程
- PAT甲级1037 Magic Coupon:[C++题解]贪心
- python你的人生_人生苦短:运行你的第一个 Python 脚本
- 我爱计算机视觉干货集锦分类汇总(2019年5月7日)
- 中国移动上市第二日逼近破发线
- expect - linux远程执行命令
- 在网页中引用js文件、css文件或图片文件时为什么要加上问号+值或key-value
- 中华石杉-- --搜索引擎的笔记
- Navicat15下载安装
- 【解决篇】映美FP-530K+打印发票卡纸,色带安装问题
- Oracle间隔(interval)分区
- ODL(C版本)安装过程
- OpenCV 形态学操作应用——提取水平与垂直线
- Echarts实现省级到市级地图下钻
- 形容芝士蛋糕好吃的句子精选
- Java实现动态切换数据源
- 如何轻松地的现货白银中预测走势?
热门文章
- Java 8 Lambda表达式-接口实现
- Bash shell - 2
- 15.3 Task Task.Yield和Task.Delay说明
- MIMO雷达比幅单脉冲测角精度分析(系统工程与电子技术)
- MySQL xtrabackup之--databases 勿手贱
- js操作HTML的select
- struts2前台获取setattribute为空指针异常_告诉你,这样设计 Java 异常更优雅,更牛逼!...
- 不得自行对涉密计算机进行格式化,保密资格认证-涉密人员考试试题
- 【STM32】FreeRTOS 中断配置和临界段
- 第三章 线性代数回顾-机器学习老师板书-斯坦福吴恩达教授