题意:N个人,M次操作,操作一:A X Y,X,Y不是同一帮派,操作二:D X Y,判断X和Y的关系。

思路:如果X和Y不是同一帮派,那X与Y+N、Y与X+N是同一帮派,如果X与Y不在同一帮派且X与Y+N不是同一帮派则不能确定关系,如果X与Y是同一帮派则输出same那句话,如果X与Y+N是同一帮派则输出different那句话。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m;
int pre[];
int rank[];
char s[];
void init(int n)
{
for(int i=;i<=n;i++)
pre[i]=i,rank[i]=;
}
int find(int x)
{
return x==pre[x]?x:pre[x]=find(pre[x]);
}
void unite(int x,int y)
{
x=find(x);
y=find(y);
if(x==y)
return ;
if(rank[x]<rank[y])
pre[x]=y;
else
{
pre[y]=x;
if(rank[x]==rank[y])
rank[x]++;
}
}
int same(int x,int y)
{
return find(x)==find(y);
}
int main()
{
//std::ios_base::sync_with_stdio(false);
int t,x,y;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
init(n*);
for(int i=;i<=m;i++)
{
scanf("%s%d%d",s,&x,&y);
if(s[]=='A')
{
if(!same(x,y)&&!same(x,y+n)) //确定是否已有确定的关系
printf("Not sure yet.\n");
else if(same(x,y)) //x与y同帮派
printf("In the same gang.\n");
else if(same(x,y+n)) //x与y不同帮派
printf("In different gangs.\n");
}
else
{
unite(x,y+n);
unite(x+n,y);
}
}
}
return ;
}

Find them, Catch them POJ - 1703的更多相关文章

  1. K - Find them, Catch them POJ - 1703 (带权并查集)

    题目链接: K - Find them, Catch them POJ - 1703 题目大意:警方决定捣毁两大犯罪团伙:龙帮和蛇帮,显然一个帮派至少有一人.该城有N个罪犯,编号从1至N(N<= ...

  2. (并查集 带关系)Find them, Catch them -- poj -- 1703

    链接: http://poj.org/problem?id=1703 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3676 ...

  3. Find them, Catch them(POJ 1703 关系并查集)

    Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 38668   Accepted: ...

  4. DisJSet:Find them, Catch them(POJ 1703)

    抓住他们! 题目大意:两个黑社会帮派,互相打架,现在你很多条信息,要你确定两个人是否属于不同帮派 这题很有趣,题目不是直接给你两个人是否是一个帮派的,他给你的是不同帮派的,也就是给你很多个不同的要你找 ...

  5. poj.1703.Find them, Catch them(并查集)

    Find them, Catch them Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I6 ...

  6. POJ 1703 Find them, Catch them(种类并查集)

    Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 41463   Accepted: ...

  7. POJ 2236 Wireless Network ||POJ 1703 Find them, Catch them 并查集

    POJ 2236 Wireless Network http://poj.org/problem?id=2236 题目大意: 给你N台损坏的电脑坐标,这些电脑只能与不超过距离d的电脑通信,但如果x和y ...

  8. 【并查集】模板 + 【HDU 1213、HDU 1232、POJ 2236、POJ 1703】例题详解

    不想看模板,想直接看题目的请戳下面目录: 目录: HDU 1213 How Many Tables[传送门] HDU 1232 畅通工程 [传送门] POJ 2236 Wireless Network ...

  9. 【原创】POJ 1703 && RQNOJ 能量项链解题报告

    唉 不想说什么了 poj 1703,从看完题到写完第一个版本的代码,只有15分钟 然后一直从晚上八点WA到第二天早上 最后终于发现了BUG,题目要求的“Not sure yet.”,我打成了“No s ...

随机推荐

  1. Ubuntu 16.04下配置intel opencl环境

    一. 靠谱的安装教程 1. 官网教程 https://software.intel.com/en-us/articles/sdk-for-opencl-2019-gsg,打开后往下拉到[4. Prod ...

  2. install virtual enviroment on windows

    H:\>pip install virtualenv  --install virtualenvCollecting virtualenv Downloading https://files.p ...

  3. pyqgis学习

    1. 错误:ImportError: No module named qgis.core解决方法:python的qgis,初始化变量:D:\PROGRA~1\QGIS3~1.0\OSGeo4W.bat ...

  4. Unity UGUI 小知识

    1.有个控件叫Selectable 这个控件在button,slider等身上有,也可以自行添加,可通过API搜索所有带这个控件的物体统一控制. 2.实现ScrollView只使用Scrollbar操 ...

  5. Python学习—数据库篇之SQL补充

    一.SQL注入问题 在使用pymysql进行信息查询时,推荐使用传参的方式,禁止使用字符串拼接方式,因为字符串拼接往往会带来sql注入的问题 # -*- coding:utf-8 -*- # auth ...

  6. step_by_step_xUnit_Net_ABP

    这段日子的开发一直使用Asp.net Boilerplate ,称之为项目模板自然就有开发中常用的功能,测试框架也在其中,土牛的ABP源代码都有通过测试,很遗憾的是我之前没有写过测试,不会就要去找资料 ...

  7. 【docker 入门 - 01】- Docker 在 Centos7 上安装与测试

    一.学习文档 官网网站: https://www.docker.com 中文网站:http://www.docker-cn.com 官方安装文档:https://docs.docker.com/ins ...

  8. 通信导论-IP数据网络基础(3)

    ICMP(IP辅助协议)--网际控制报文协议 ICMP报文种类:ICMP差错报文(终点不可达.时间超过等5种)和ICMP询问报文(回送请求和回答请求.时间戳请求和回答报文2种) ICMP是一种集差错报 ...

  9. The declared package does not match the expected package Java

    今天使用vscode 编写java代码做测试时候,发现这个问题,大概总结一下. 目录结构 bao -> Point.java test.java package bao; public clas ...

  10. labellmg的使用

    ---恢复内容开始--- 在powershell环境下进入到labelImg解压后的文件,我这里是D:\labelImg-master\labelImg-master 执行命令: pyrcc5 -o ...