poj 2492 A Bug's Life
来源:互联网 发布:兵不可偃乎 编辑:程序博客网 时间:2024/05/18 04:00
并查集的高级应用.
#include <cstdio>using namespace std;#define max_n 2300int father[max_n];int relation[max_n];int n,m;void init(){for(int i=1;i<=n;i++){father[i] = i;relation[i] = 0;}}int find(int x){if(x!=father[x])father[x] = find(father[x]);return father[x];}void get_in(int a,int b){int x = find(a);int y = find(b);if(x!=y)father[y] = x;}int main(){int t;int i;scanf("%d",&t);for(i=1;i<=t;i++){bool flag = false;int a,b;scanf("%d%d",&n,&m);init();while(m--){scanf("%d%d",&a,&b);if(flag)continue;if(find(a)==find(b)){flag = true;}if(relation[a]==0&&relation[b]==0){relation[a] = b;relation[b] = a;}else if(relation[a]==0){relation[a] = b;get_in(a,relation[b]);}else if(relation[b]==0){relation[b] = a;get_in(b,relation[a]);}else{get_in(a,relation[b]);get_in(b,relation[a]);}}printf("Scenario #%d:\n",i);if(flag){printf("Suspicious bugs found!\n\n");}else{printf("No suspicious bugs found!\n\n");}}}
0 0
- 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
- POJ 2492 A Bug's Life
- POJ 2492 A Bug's Life
- 并查集(Disjoint Set)
- 诚惶诚恐,开始翻译Effective DevOps
- Nginx开启gzip压缩
- 常用的基本DOS命令
- PHP Study- Issue 1 -Redirect Unable to load the module
- poj 2492 A Bug's Life
- WebSocket spring示例demo (已使用sockJs库)
- springMVC中pojo参数绑定
- mysql5.7.12 zip免安装版本配置
- acm_stl
- 4G网络架构
- 牛吃草问题 (牛顿问题)
- Google深度学习笔记 从线性分类器到深度神经网络
- 今天开始来写技术感受了望和同行技术人员一起交流恳请技术人员们谅解下让我首先发布下: 国学十二道 及 一句话概括国学经典书目精髓