hdu1272 小希的迷宫 并查集
来源:互联网 发布:nginx 函数 编辑:程序博客网 时间:2024/06/05 14:48
#include<iostream>#include<cstdio>#include<cmath>#include<algorithm>#include<memory.h>#include<map>#include<queue>#include <deque>#include <list>#include <ctime>#include <stack>#include <vector>#include<set>#define Maxn 100005typedef long long ll;#define rep(i,j,n) for(int i=j;i<=n;i++)#define per(i,j,k) for(int i=j;i>=k;--i)#define lowbit(a) a&-a#define Max(a,b) a>b?a:b#define Min(a,b) a>b?b:aconst int inf = 0x3f3f3f3f;const double pi = acos(-1.0);using namespace std;int father[Maxn],flag,sign[Maxn];void init(){ for(int i=1;i<Maxn;i++) {father[i]=i; sign[i]=0; }}int getf(int x){ if(x!=father[x]) father[x]=getf(father[x]); return father[x];}void Union(int x,int y){ x=getf(x); y=getf(y); if(x!=y) father[x]=y; else flag=0;//判断是否成环}int main(){ int a,b; while(~scanf("%d%d",&a,&b)) { if(a==-1&&b==-1) break; if(a==0 && b==0){printf("Yes\n");continue;} init(); sign[a]=sign[b]=1; flag=1; Union(a,b); while(~scanf("%d%d",&a,&b)&&a&&b) { Union(a,b); sign[a]=sign[b]=1; } int k=0,ans=0; for(int i=1;i<Maxn;i++) { if( sign[i]&& father[i]==i) //判断根节点k数目 k++; if(k>1) flag=0; } if(flag) printf("Yes\n"); else printf("No\n"); } return 0;}
0 0
- hdu1272(小希迷宫 并查集)
- HDU1272 小希的迷宫 并查集
- 【hdu1272】 小希的迷宫 (并查集)
- 小希的迷宫 hdu1272 并查集
- hdu1272小希的迷宫(并查集)
- 【并查集】-HDU1272-小希的迷宫
- hdu1272小希的迷宫 基础并查集
- hdu1272 小希的迷宫(并查集)
- hdu1272 小希的迷宫(并查集)
- HDU1272小希的迷宫--并查集入门题
- HDU1272 小希的迷宫 【并查集】
- Hdu1272 - 小希的迷宫 - 并查集
- HDU1272 小希的迷宫 (并查集)
- HDU1272 小希的迷宫(基础并查集)
- hdu1272 - 小希的迷宫 (基础并查集)
- hdu1272 -- 小希的迷宫(并查集)
- hdu1272小希的迷宫(并查集)
- HDU1272 小希的迷宫 并查集
- jquery倒计时功能
- 利用Theano理解深度学习——Logistic Regression
- 算法时间复杂度T(n)大小顺序
- Java语言简介
- SQL Server基础--SQL语句
- hdu1272 小希的迷宫 并查集
- Android 开发第五弹:简易时钟(闹钟)
- superoj906 flood
- yum.Errors.MiscError: xz compression not available
- 欢迎使用CSDN-markdown编辑器
- 二分插入
- git 退回到倒数第二次提交
- javascript获取查询参数
- VC-Socket send函数和recv函数详解