POJ 2492 A Bug's Life(扩展并查集)
来源:互联网 发布:mac翻墙回国软件 编辑:程序博客网 时间:2024/05/02 01:21
#pragma warning(disable:4996)#include <iostream>#include <cstdio>#include <cstring>#include <string>using namespace std;//扩展并查集int fa[2001], relation[2001];//同性为0,异性为1int find(int x){if (x == fa[x])return x;int tmp = fa[x];fa[x] = find(tmp);relation[x] = (relation[x] + relation[tmp]) % 2;return fa[x];}void merge(int x, int y){int fx = find(x);int fy = find(y);if (fx == fy)return;fa[fx] = fy;relation[fx] = (relation[x] + relation[y] == 1) ? 0 : 1;}int main(){int t;scanf("%d", &t);for (int kase = 1; kase <= t; kase++){memset(relation, 0, sizeof relation);for (int i = 1; i < 2001; i++)fa[i] = i;string ans = "";int n, m;scanf("%d %d", &n, &m);for (int i = 1; i <= m; i++){int x, y;scanf("%d %d", &x, &y);if (find(x) == find(y)){if (relation[x] == relation[y])ans = "Suspicious bugs found!";}else{merge(x, y);}}if (ans.size() > 0){cout << "Scenario #" << kase << ':' << endl << ans << endl << endl;}else{cout << "Scenario #" << kase << ':' << endl << "No suspicious bugs found!" << endl << endl;}}return 0;}
0 0
- [POJ 2492] A Bug's Life [扩展并查集]
- POJ 2495 A Bug's Life【并查集扩展】
- POJ 2492 A Bug's Life(扩展并查集)
- POJ 2492 A Bug's Life (并查集)
- POJ 2492 A Bug's Life (并查集)
- POJ 2492 A Bug's Life(并查集)
- POJ 2492 A Bug's Life(并查集)
- poj 2492 A Bug's Life(并查集)
- poj 2492 A Bug's Life(并查集)
- poj 2492 A Bug's Life(并查集)
- POJ 2492 A Bug's Life(并查集)
- poj 2492 并查集 A Bug's Life
- POJ-2492 a bug's life 并查集
- poj 2492 并查集 a bug's life
- poj 2492 A Bug's Life(种类并查集)
- poj 2492 -- A Bug's Life(并查集)
- poj 2492 - A Bug's Life(并查集)
- 【种类并查集】-POJ-2492-A bug's life
- linux 下的source命令的作用是什么?
- 自定义导航按钮UIBarButtonItem
- 边框属性border
- 计算机网络(一)
- mysql mysqldump只导出表结构或只导出数据的实现方法
- POJ 2492 A Bug's Life(扩展并查集)
- linux下Qt安装问题
- 提升linux下tcp服务器并发连接数限制
- c# Serialization: 序列化内容至CData
- HDU - 2955 Robberies
- KVO的使用
- leetcode:Number of Islands
- 通俗说说DSP、SSP、RTB、DMP是什么
- java面试总结