【POJ 1703】 Find them,Catch them
2024-08-31 05:26:13
【题目链接】
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 ; }
最新文章
- iOS 使用xib后获取view的frame出错的问题
- 一个App完成入门篇(二)-搭建主框架
- 浏览器加载和渲染html的顺序
- EF的入门使用 (电影管理)
- here 文档
- 【总结】学习Socket编写的聊天室小程序
- CentOS_6.5安装Nginx+PHP+MySQL
- leetcode:Palindrome Number
- DLL远程注入与卸载
- ajax跨域解决方案(服务端仅限java)
- Android 图片选择器
- APUE读书笔记-第14章-高级I/O
- 第四十七节,random 随机数模块
- 安装lnmp(linux nginx mysql php)
- angularjs实现首页轮播图
- 实现数组元素互换位置(乘机理解java参数传递)
- Linux下python2和python3共存
- myslide 插件开发知识点总结和 css3 动画性能问题的研究
- dede5.7 GBK 在php5.4环境下 后台编辑器无法显示文章内容
- GDI+绘制简单图形
热门文章
- Laravel5.1学习笔记5 请求
- 百鸡百钱===百马百担====for循环嵌套
- 【Oracle】DG中物理备库、快照备库的相互转换
- Android进度条控件ProgressBar使用
- 备份xx
- MQTTnet 的Asp.Net Core 认证事件的扩展
- spring cloud(五) hystrix
- Day 23 类的继承,派生,组合,菱形继承,多态与多态性
- pymysql.err.ProgrammingError: (1064)(字符串转译问题)
- 线程同步、信号量、system v IPC