poj 1703 Find them, Catch them
来源:互联网 发布:网络通信代维招聘 编辑:程序博客网 时间:2024/06/05 04:30
我参照了下边这篇博客:
http://www.voidcn.com/blog/u011008379/article/p-5747778.html
这道题就需要虚点的存在。
比如:输入D 1 2
那么就为2创造一个虚点2',让2‘和1同在一个集合。为1创造一个虚点1’和2同在一个集合。
判断a和b的时候,若a,b同在一个集合,那么a,b在同一个帮派。若a和b‘在一个集合,则a,b在不同的帮派里。
#include <stdio.h>#define N 100000int ax[N*2+5];int nfind(int x);void get_in(int a,int b);bool nsame(int a,int b);int main(){int t;scanf("%d", &t);while (t--){int n, m;scanf("%d%d", &n, &m);for (int i = 1; i <= n * 2; i++){ax[i] = i;}while (m--){char p[2];int s, q;scanf("%s%d%d", p, &s, &q);if (p[0] == 'D'){get_in(s, q + n);get_in(s + n, q);}else{if (nsame(s, q)){printf("In the same gang.\n");}else if (nsame(s, q + n)){printf("In different gangs.\n");}else{printf("Not sure yet.\n");}}}}}int nfind(int x){if (x != ax[x])ax[x] = nfind(ax[x]);return ax[x];}void get_in(int a, int b){int sa = nfind(a);int sb = nfind(b);if (sa != sb)ax[sa] = sb;}bool nsame(int a, int b){int sa = nfind(a);int sb = nfind(b);if (sa == sb)return true;elsereturn false;}
0 0
- POJ 1703 Find them, Catch them
- poj 1703 Find them, Catch them
- POJ-1703 Find them, Catch them
- Poj 1703 Find them, Catch them
- poj 1703 Find them, Catch them
- POJ 1703 Find them, Catch them
- poj 1703 Find them, Catch them
- poj 1703 Find them, Catch them
- POJ 1703 - Find them, Catch them
- POJ 1703 Find them, Catch them
- POJ 1703(Find them, Catch them)
- POJ 1703 Find them, Catch them
- poj 1703 Find them, Catch them
- poj 1703 Find them, Catch them
- POJ 1703: Find them, Catch them
- poj 1703 find them,catch them
- POJ--1703--Find them, Catch them
- POJ 1703 Find them, Catch them
- doxygen将头文件生成html文档
- 1.python基础学习__函数中的参数
- Android程序优化之对屏幕旋转的处理总结
- OneThink修改后台文档列表搜索规则
- java 前端及后台轮询方法总结
- poj 1703 Find them, Catch them
- 【C语言】动态内存分配alloca
- UVa 712 S-Trees(满二叉树数组保存与编号)
- g4l 备份还原linux系统
- cug1699数组反转
- PAT乙级1006:换个格式输出整数 (15)
- Stanford 机器学习 Dimensionality Reduction
- java性能优化之二 循环里面不使用hibernate创建对象
- solr占用CPU持续过高原因查询