UVa 10158 War / 并查集
来源:互联网 发布:php开源代码 编辑:程序博客网 时间:2024/04/30 15:42
我是百度的 嗯 并查集已经忘了 现在复习下
#include <cstdio>const int MAX = 20010;int frien[MAX];int find(int x){if(x != frien[x])frien[x] = find(frien[x]);return frien[x];}int main(){int n;int i;int a,b,c;while(scanf("%d",&n)!=EOF){for(i = 0;i < 2*n; i++){frien[i] = i;}while(scanf("%d %d %d",&c,&a,&b),c||a||b){int f1 = find(a);int f2 = find(b);int e1 = find(a+n);int e2 = find(b+n);if(c == 1)//朋友 {if(f1 == e2) //f1集合的敌人是e2集合 那么ab不可能是朋友 输出-1{puts("-1");continue;}frien[f1] = f2;frien[e1] = e2;}else if(c == 2){if(f1 == f2)//ab是朋友 他们不可能是敌人 矛盾{puts("-1");continue;}frien[f1] = e2;frien[e1] = f2;}else if(c == 3){if(f1 == f2)puts("1");elseputs("0");}else{if(f1 == e2)puts("1");elseputs("0");}}}return 0;}/*101 0 11 1 22 0 53 0 23 8 94 1 54 1 24 8 91 8 91 5 23 5 20 0 0*/
0 0
- uva 10158 - War(并查集)
- UVA 10158 - War(并查集)
- UVa 10158 War / 并查集
- UVA 10158 War(并查集)
- War - UVa 10158 并查集
- UVA 10158 War (并查集)
- uva 10158 War (并查集)
- UVA---10158-War(并查集)
- UVA 10158 War 并查集
- UVa - 10158 - War ( 并查集 )
- uva 10158 War(并查集的简单应用)
- UVA - 10158 War 并查集升级版
- uva10158(War)并查集
- 【】Star War 并查集
- UVA10158 - War(并查集)
- CSU1601: War(并查集)
- CSU1601: War(并查集)
- uva 10158(并查集)
- sh 将mysql中所有的索引保存到一个文件中
- Zen of PM - Getting the team up to speed
- linux下恢复删除文件
- coursera公开课:機器學習基石 (Machine Learning Foundations) 作业一(Question15)
- TB GB MB KB B BIT
- UVa 10158 War / 并查集
- 数据仓库中的三种事实表
- iphone4 电话截获
- 2013.12.16oracle 会话属性 模块名 操作名 会话跟踪
- 顶点坐标变换(3)
- Linux面试基础题-2
- Spring TestContext测试框架
- 关于vector定义二维数组的问题
- 一个UltraTree结点拖动到另一个UltraTree上面