【题目链接】

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. 【SQL】含有NULL值的排序

    查询结果中有NULL值,当进行升序排序时,NULL值默认为“最大值”,排在最后面.要想改变NULL值的显示顺序,只需要在SQL语句后面加上NULLS FIRST(排在前面),NULLS LAST(排在 ...

  2. css属性代码大全总结(一)

    一 CSS文字属性: color : #999999; /*文字颜色*/ font-family : 宋体,sans-serif; /*文字字体*/ font-size : 9pt; /*文字大小*/ ...

  3. PythonOpenCV:MLP用于最近邻搜索

    一:简单C++版本的链接: http://blog.csdn.net/kaka20080622/article/details/9039749 OpenCV的ml模块实现了人工神经网络(Artific ...

  4. Type inference

    Type inference refers to the automatic detection of the data type of an expression in a programming ...

  5. C# 去掉代码前边空格(格式化代码)

    private void button1_Click(object sender, EventArgs e) { textBox2.Text = ""; string str = ...

  6. HTML 5语义化标签

    HTML 5的革新之一:语义化标签一节元素标签. 在HTML 5出来之前,我们用div来表示页面章节,但是这些div都没有实际意义.(即使我们用css样式的id和class形容这块内容的意义).这些标 ...

  7. Django 模型层(标签、过滤器、模板的继承与导入)

    过滤器/自定义过滤器 模板语法中的过滤器类似于python中的内置方法,在我们把数据从后端通过rander传入到前端html文件中之后,在前端我们可以通过模板语法,对传入的数据再进行以通骚操作. 首先 ...

  8. visual studio2017 创建Vue项目

    1:打开Visual studio 2017后 按图片操作新建项目 也可以使用快捷键Ctrl+Shift+N  进入创建项目页面 2:选择JavaScript 里的Node.js创建对应的Vue项目 ...

  9. 【Codeforces 342A】Xenia and Divisors

    [链接] 我是链接,点我呀:) [题意] [题解] 最后a,b,c只有以下3种情况 1,2,4 1,2,6 1,3,6 那么用cnt[8]统计每个数字出现的次数. 输出cnt[4]次1,2,4 (如果 ...

  10. Spring Cloud-Ribbon ILoadBalancer负载均衡器核心源码(四)

    Ribbon负载均衡相关类 AbstractloadBalancer ILoadBalancer的抽象实现类 public abstract class AbstractLoadBalancer im ...