【题目链接】

http://poj.org/problem?id=1703

【算法】

并查集 + 拆点

【代码】

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
const int MAXN = 1e5 + ; int i,T,x,y,n,m;
int fa[MAXN<<];
char opt[]; inline int get_root(int x)
{
if (fa[x] == x) return x;
return fa[x] = get_root(fa[x]);
} int main()
{ scanf("%d",&T);
while (T--)
{
scanf("%d%d",&n,&m);
for (i = ; i <= * n; i++) fa[i] = i;
for (i = ; i <= m; i++)
{
scanf("%s",&opt);
if (opt[] == 'A')
{
scanf("%d%d",&x,&y);
if (get_root(x) == get_root(y)) printf("In the same gang.\n");
else if (get_root(x+n) == get_root(y)) printf("In different gangs.\n");
else printf("Not sure yet.\n");
} else
{
scanf("%d%d",&x,&y);
fa[get_root(x+n)] = get_root(y);
fa[get_root(y+n)] = get_root(x);
}
}
} return ; }

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

  1. 【POJ - 1703】Find them, Catch them(种类并查集)

    Find them, Catch them 直接翻译了 Descriptions 警方决定捣毁两大犯罪团伙:龙帮和蛇帮,显然一个帮派至少有一人.该城有N个罪犯,编号从1至N(N<=100000. ...

  2. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  3. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  4. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  5. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  6. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  7. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  8. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

  9. BZOJ2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 513  Solved: 201[Submit][ ...

随机推荐

  1. 用CSS伪类制作一个不断旋转的八卦图?

    前言 介绍一下如何制作一个不断旋转的八卦图.快速预览代码及效果,点击:八卦图 代码如下: HTML部分 <!DOCTYPE html> <html> <head> ...

  2. java基础学习四

    一.java中的基本数据类型 二.double和float精度不准的问题 double和float本身确实存在某种缺陷,不能用于精确计算. 解决办法: 用java.math.BigDecimal,通过 ...

  3. ArrayList<HashMap<String,Object>>集锦

    1.   Android中如何从一个Activity中ArrayList<HashMap<String,Object>>传递到另一个activity?      eg:     ...

  4. HTML 5的基本标签

    1.  文件开始标签<html> 在任何的一个HTML文件里,最先出现的HTML标签就是<html>,它用于表示该文件是以超文本标识语言(HTML)编写的.<html&g ...

  5. 努比亚 Z17s (Nubia NX595J) 解锁BootLoader 并刷入recovery ROOT

    首先下载好工具链接:https://pan.baidu.com/s/1nw7BoZB 密码:zuun 备用下载链接:https://pan.baidu.com/s/1c3mUQGg 本篇教程教你如何傻 ...

  6. 关于VM虚拟机在使用网络时与锐捷网络冲突的解决问题

    在使用NAT网络模式的时候,锐捷会因为冲突强制关闭NAT服务,导致虚拟机无法上网,解决的办法是让NAT服务一直保持启动,写一个bat脚本来一直检测服务是否在运行,并且进行启动操作. 当不需要用虚拟机的 ...

  7. 乐乎共享wifi充电宝项目

  8. C#让电脑发声,播放声音

    //1. [DllImport("Kernel32.dll")] //引入命名空间 using System.Runtime.InteropServices; public sta ...

  9. Skyline Web 端数据浏览性能优化

    三维数据的效率一直是个瓶颈,特别是在Web端浏览一直是个问题,在IE内存限制1G的条件下,对于三维数据动不动几十G的数据量,这1G显得多么微不足道.虽然现在三维平台都是分级加载,或者在程序中采用数据分 ...

  10. Mahmoud and a Dictionary

    Mahmoud and a Dictionary time limit per test 4 seconds memory limit per test 256 megabytes input sta ...