直接解释输入了:

第一行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. 存档:Telerik Test Studio的摸索笔记

    http://www.51testing.com/?uid-170604-action-spacelist-starttime-1328025600-endtime-1330531200 http:/ ...

  2. 三维重建7:Visual SLAM算法笔记

    VSLAM研究了几十年,新的东西不是很多,三维重建的VSLAM方法可以用一篇文章总结一下. 此文是一个好的视觉SLAM综述,对视觉SLAM总结比较全面,是SLAM那本书的很好的补充.介绍了基于滤波器的 ...

  3. 关于OpenCV的Mat画图问题

    由于OpenCV的java版本画图有太多错误,只能自己编写画图的代码,在一个函数中,编写出画圆和深度距离的代码, 代码如下: public int CircleMyMat(Mat Show, Poin ...

  4. 读书笔记「Python编程:从入门到实践」_7.用户输入和while循环

    7.1 函数input()的工作原理 函数input() 让程序暂停运行,等待用户输入一些文本.获取用户输入后,Python将其存储在一个变量中,以方便你使用. message = input(&qu ...

  5. java中反射讲解及实例

    Java反射机制详解 java 反射 定义 功能 示例 概要: Java反射机制详解 | |目录 1反射机制是什么 2反射机制能做什么 3反射机制的相关API ·通过一个对象获得完整的包名和类名 ·实 ...

  6. NFS网络文件系统方案

    1,关闭防火墙和selinuxiptables -Fsystemctl stop firewalldsystemctl disable firewalldsetenforce 0 服务器系统    名 ...

  7. TensorFlow技术解析与实战学习笔记(15)-----MNIST识别(LSTM)

    一.任务:采用基本的LSTM识别MNIST图片,将其分类成10个数字. 为了使用RNN来分类图片,将每张图片的行看成一个像素序列,因为MNIST图片的大小是28*28像素,所以我们把每一个图像样本看成 ...

  8. PHP AES cbc模式 pkcs7 128加密解密

    今天在对接一个第三方接口的时候,对方需要AES CBC模式下的加密.这里简单写一个demo class Model_Junjingbao extends Model { private static ...

  9. cxdbtreelist的按记录查找节点

    lst_projet.DataController.DataSet.Locate('pm_id',vPm_ID,[]); bl:= lst_projet.DataController.DataSet. ...

  10. Visifire实现统计图

    /// <summary> /// 柱形图 /// </summary> public static Chart InitCompareChart(string fundNam ...