hdu 1272 小希的迷宫 并查集
来源:互联网 发布:淘宝三星手机官网 编辑:程序博客网 时间:2024/06/11 01:33
#include <cstdio>#include <iostream>#include <queue>#include <set>using namespace std;struct node{int x,y;};int fa[100015];int find(int x){while(fa[x]!=x){x = fa[x];}return x;}int d[100015];node b[100015];int unit(int x,int y){if(d[x] < d[y]){fa[x] = y;}else if(d[y] < d[x]){fa[y] = x;}else{fa[x] = y;d[x] ++;}}int main(){node a;while(scanf("%d%d",&a.x,&a.y)){if(a.x == -1&& a.y ==-1)break;int ma = 0;int cc = 0;b[cc] = a;while(b[cc].x || b[cc].y){cc++;scanf("%d%d",&b[cc].x,&b[cc].y);ma = max(ma,max(b[cc].x,b[cc].y));} for(int i = 0;i <= ma+1;i++){fa[i] = i;d[i] = 1;}int flag = 1;int j = 0;while(j < cc){a = b[j];int fx = find(a.x);int fy = find(a.y);if(fx == fy){flag = 0;break;}else{unit(fx,fy);}j++;}if(flag){set<int> se;for(int i = 0;i < cc && se.size() <= 1;i++){se.insert(find(b[i].x));se.insert(find(b[i].y));}if(se.size() <= 1){cout << "Yes" << endl;}else{cout << "No" << endl;}}else{cout << "No" << endl;}}return 0;}
0 0
- hdu 1272 小希的迷宫 并查集
- hdu 1272 小希的迷宫(并查集)
- hdu 1272 小希的迷宫(并查集)
- hdu 1272 小希的迷宫 (并查集)
- hdu 1272 小希的迷宫(并查集)
- hdu 1272 小希的迷宫(并查集)
- HDU 1272 小希的迷宫 并查集
- HDU 1272小希的迷宫(简单并查集)
- HDU-1272 小希的迷宫 并查集
- HDU 1272-小希的迷宫 并查集初级
- hdu 1272 小希的迷宫 (并查集)
- HDU 1272小希的迷宫 并查集
- 【并查集】 HDU 1272 小希的迷宫
- 并查集 HDU 1272 小希的迷宫
- hdu 1272 小希的迷宫(并查集)
- 【并查集】hdu 1272 小希的迷宫
- hdu 1272小希的迷宫 并查集
- HDU-#1272 小希的迷宫(并查集)
- CDOJ 1114 Cent Savings
- 容易想复杂的"回环变位"
- log4cplus 学习
- 51单片机 超声波测距组件
- 测试用例的编写
- hdu 1272 小希的迷宫 并查集
- Docker MAC脚本
- 字节流和字符流分别读取文件
- cocos2d::DrawPrimitives和DrawNode分别实现画板功能
- 使用ViewPager循环滑动时注意的问题
- 布局管理器之CardLayout(卡片布局管理器)
- acm算法之树状数组
- Docker Command List
- Java线程总结