直接解释输入了:

第一行cases.

然后是n和m代表有n个人,m个操作

给你两个空的集合

每个操作后面跟着俩数

D操作是说这俩数不在一个集合里。

A操作问这俩数什么关系

不能确定:输出Not sure yet.

在一个集合里:输出In the same gang.

不在一个集合里:输出In different gangs.

这题挺像http://poj.org/problem?id=2492同性恋的虫子那道题的。

// by SiriusRen
#include <cstdio>
#include <cstring>
using namespace std;
int cases,xx,yy,n,m,f[105000],d[100500];
char jy,jy1;
int find(int x){
if(f[x]==x)return x;
int y=f[x];
f[x]=find(f[x]);
d[x]=(d[x]+d[y])%2;
return f[x];
}
int main(){
scanf("%d",&cases);
while(cases--){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)f[i]=i;
memset(d,0,sizeof(d));
for(int i=1;i<=m;i++){
scanf("%c%c%d%d",&jy1,&jy,&xx,&yy);
int fx=find(xx),fy=find(yy);
if(jy=='A'){
if(fx!=fy)puts("Not sure yet.");
else if(d[xx]!=d[yy])puts("In different gangs.");
else puts("In the same gang.");
}
else f[fx]=fy,d[fx]=(d[yy]-d[xx]+1)%2;
}
}
}

POJ 1703 带权并查集的更多相关文章

  1. poj 1182 (带权并查集)

    食物链 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 71361   Accepted: 21131 Description ...

  2. poj 1733(带权并查集+离散化)

    题目链接:http://poj.org/problem?id=1733 思路:这题一看就想到要用并查集做了,不过一看数据这么大,感觉有点棘手,其实,我们仔细一想可以发现,我们需要记录的是出现过的节点到 ...

  3. Navigation Nightmare POJ - 1984 带权并查集

    #include<iostream> #include<cmath> #include<algorithm> using namespace std; ; // 东 ...

  4. Parity game POJ - 1733 带权并查集

    #include<iostream> #include<algorithm> #include<cstdio> using namespace std; <& ...

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

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

  6. POJ 1703 Find them, Catch them(带权并查集)

    传送门 Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42463   Accep ...

  7. (中等) POJ 1703 Find them, Catch them,带权并查集。

    Description The police office in Tadu City decides to say ends to the chaos, as launch actions to ro ...

  8. poj 1703 - Find them, Catch them【带权并查集】

    <题目链接> 题目大意: 已知所有元素要么属于第一个集合,要么属于第二个集合,给出两种操作.第一种是D a b,表示a,b两个元素不在一个集合里面.第二种操作是A a b,表示询问a,b两 ...

  9. POJ 1703 Find them, Catch them【种类/带权并查集+判断两元素是否在同一集合/不同集合/无法确定+类似食物链】

      The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the ...

随机推荐

  1. JAVA;使用java.awt.Image的不稳定性

    在使用awt的image时候,不是能时时获取到图像的宽和高, GetWidth()函数偶尔得到的值为-1,暂时没有找到解决方法. 代码: public class picture extends JF ...

  2. php常用字符串和例子

    //输出一个或多个字符串 //注:echo 不是一个函数(它是一个语言结构), 因此你不一定要使用小括号来指明参数,单引号,双引号都可以 $a = "admin1"; $b = & ...

  3. 团体程序设计天梯赛-练习集-L1-034. 点赞

    L1-034. 点赞 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 微博上有个“点赞”功能,你可以为你喜欢的博文点个赞表示支持 ...

  4. 文献阅读 | Benefits and limitations of genome-wide association studies

    参考:今日阅读:GWAS的优劣势 - Omics Liu  Omics 待续~

  5. ES6中的Symbol

    ---恢复内容开始--- Symbol 1.1 概述 保证每个属性的名字都是独一无二的就好了,这样就从根本上防止属性名的冲突.这就是 ES6 引入Symbol的原因 在es6之前,JavaScript ...

  6. 转载:Java中的Checked Exception——美丽世界中潜藏的恶魔?

    转自 Amber-Garden 的 博客 https://www.cnblogs.com/loveis715/p/4596551.html 在使用Java编写应用的时候,我们常常需要通过第三方类库来帮 ...

  7. 以豌豆荚为例,用 Scrapy 爬取分类多级页面

    本文转载自以下网站:以豌豆荚为例,用 Scrapy 爬取分类多级页面 https://www.makcyun.top/web_scraping_withpython17.html 需要学习的地方: 1 ...

  8. PHP中把数据库查询结果输出为json格式

    <?php header("Content-type:text/html;charset=utf-8");//字符编码设置 $servername = "local ...

  9. python爬虫04 | 长江后浪推前浪,Reuqests库把urllib库拍在沙滩上

    最近 有些朋友 看完小帅b的文章之后 把小帅b的表情包都偷了 还在我的微信 疯狂发表情包嘚瑟 我就呵呵了 只能说一句 盘他 还有一些朋友 看完文章不点好看 还来催更 小帅b也只能说一句 继续盘他   ...

  10. nyoj 711 枚举+并查集

     #include<stdio.h>//从大到小不断枚举边直到找到s-t的路径,判断从s可以到t可以用并查集来判断 #include<stdlib.h>//枚举最大的一条边肯定 ...