POJ2492 A Bug's Life
来源:互联网 发布:跳转到一个页面的js 编辑:程序博客网 时间:2024/04/28 20:49
/*并查集*/#include <iostream>#include <cstdio>using namespace std;const int MAXN = 2005;int father[MAXN], Rank[MAXN];int cas = 0, t;int n, m;bool flag;void init(){for (int i = 0; i < n; ++i) {father[i] = i;Rank[i] = 0;}return;}int getfather(int x){if (x == father[x]) return x;int tmp;tmp = getfather(father[x]);Rank[x] = (Rank[x] + Rank[father[x]]) % 2;father[x] = tmp;return father[x];}void merge(int x, int y){int fx, fy;fx = getfather(x);fy = getfather(y);if (fx == fy) {if (Rank[x] == Rank[y]) flag = false;}else {father[fx] = fy;Rank[fx] = (Rank[x] + Rank[y] + 1) % 2;}return;}int main(){cin >> t;while (t--) {cin >> n >> m;init();flag = true;int x, y;for (int i = 0; i < m; ++i) {scanf("%d%d", &x, &y);if (!flag) continue;merge(x, y);}cout << "Scenario #" << ++cas << ":" << endl;if (flag) cout << "No suspicious bugs found!" << endl << endl;else cout << "Suspicious bugs found!" << endl << endl;}return 0;}
0 0
- poj2492 A Bug's Life
- POJ2492 A Bug's Life
- poj2492 - A Bug's Life
- poj2492 A Bug's Life
- POJ2492 A Bug's Life
- POJ2492---A Bug's Life
- poj2492 A Bug's Life
- POJ2492 A Bug's Life
- POJ2492-A Bug's Life
- poj2492——A Bug's Life
- POJ2492——A Bug's Life
- HDU1829 POJ2492 A Bug's Life
- poj2492——A Bug's Life
- POJ2492--A Bug's Life--并查集
- poj2492 A Bug's Life 种类并查集
- POJ2492 A Bug's Life (并查集)
- poj2492--A Bug's Life(并查集变形)
- POJ2492 A Bug's Life 【并查集】
- ZeroMemory 与 memset
- 成功不需要美学
- 【转载】高性能网络I/O框架-netmap源码分析(2)
- 代理模式与装饰模式的异同
- malloc函数详解
- POJ2492 A Bug's Life
- Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: “object”未包含“get_Range”的定义
- 查看linux系统字符集
- 程序员应该知道的 13 个设计技巧
- 设计模式:命令模式
- AnyChat在打开音频设备的同时会自动发布视频数据吗?
- Android Studio(四)介Androi Studio技巧和窍门
- C++系列之基本数据类型、常量、变量、const、引用、typedef、枚举、类类型、编写自己的头文件
- Mark一下