【题目链接】

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 ; }

最新文章

  1. iOS 使用xib后获取view的frame出错的问题
  2. 一个App完成入门篇(二)-搭建主框架
  3. 浏览器加载和渲染html的顺序
  4. EF的入门使用 (电影管理)
  5. here 文档
  6. 【总结】学习Socket编写的聊天室小程序
  7. CentOS_6.5安装Nginx+PHP+MySQL
  8. leetcode:Palindrome Number
  9. DLL远程注入与卸载
  10. ajax跨域解决方案(服务端仅限java)
  11. Android 图片选择器
  12. APUE读书笔记-第14章-高级I/O
  13. 第四十七节,random 随机数模块
  14. 安装lnmp(linux nginx mysql php)
  15. angularjs实现首页轮播图
  16. 实现数组元素互换位置(乘机理解java参数传递)
  17. Linux下python2和python3共存
  18. myslide 插件开发知识点总结和 css3 动画性能问题的研究
  19. dede5.7 GBK 在php5.4环境下 后台编辑器无法显示文章内容
  20. GDI+绘制简单图形

热门文章

  1. Laravel5.1学习笔记5 请求
  2. 百鸡百钱===百马百担====for循环嵌套
  3. 【Oracle】DG中物理备库、快照备库的相互转换
  4. Android进度条控件ProgressBar使用
  5. 备份xx
  6. MQTTnet 的Asp.Net Core 认证事件的扩展
  7. spring cloud(五) hystrix
  8. Day 23 类的继承,派生,组合,菱形继承,多态与多态性
  9. pymysql.err.ProgrammingError: (1064)(字符串转译问题)
  10. 线程同步、信号量、system v IPC