HDU 1272 小希的迷宫
来源:互联网 发布:淘宝重复开店不查了 编辑:程序博客网 时间:2024/05/22 06:17
并查集的应用。
注意有些点可能没有出现。
#include<cstdio>#include<cstring>#include<string>#include<queue>#include<algorithm>#include<queue>#include<map>#include<stack>#include<iostream>#include<list>#include<set>#include<cmath>#define INF 0x7fffffff#define eps 1e-6using namespace std;int fa[100001];bool vis[100001];int father(int x){ if(x!=fa[x]) return fa[x]=father(fa[x]);}void intit(){ for(int i=0;i<=100001;i++) fa[i]=i,vis[i]=0;;}int main(){ intit(); int x,y; bool flag=1; int maxnum=0; while(scanf("%d%d",&x,&y)!=EOF) { maxnum=max(maxnum,max(x,y)); if(x==-1&&y==-1)return 0; if(x==0&&y==0) { int cot=0; for(int i=0;i<=maxnum;i++) { if(vis[i]&&fa[i]==i)cot++; if(cot>1)flag=0; if(!flag)break; } if(flag)puts("Yes"); else puts("No"); intit(); flag=1,maxnum=0; } else { vis[x]=vis[y]=1; int fx=father(x); int fy=father(y); if(fx==fy)flag=0; else fa[fy]=fx; } }}
0 0
- 小希的迷宫 hdu 1272
- HDU 1272 小希的迷宫
- hdu 1272 小希的迷宫
- hdu 1272 小希的迷宫
- hdu 1272 小希的迷宫
- HDU-1272-小希的迷宫
- HDU 1272 小希的迷宫
- [tree]hdu 1272 小希的迷宫
- HDU 1272 小希的迷宫
- Hdu 1272 小希的迷宫
- HDU-1272:小希的迷宫
- HDU 1272 小希的迷宫
- hdu 1272 小希的迷宫
- hdu 1272 小希的迷宫
- HDU 1272 小希的迷宫
- HDU 1272 小希的迷宫
- hdu 1272 小希的迷宫
- hdu 1272 小希的迷宫
- JavaScript内存优化
- Kaggle[2] - Predict the click through rate (KDD12 trackl2)
- POJ 1577 Falling Leaves 二叉树题解
- 正则表达式学习笔记与经验总结
- Servlet 工作原理解析
- HDU 1272 小希的迷宫
- git命令
- Windows优化大师
- python实现堆排及快排算法
- iOS多线程GCD
- 在win7+vs2010下安装WTL向导出错--Cannot copy file,没有权限。
- struts2传值问题
- java数组的赋值问题
- qsort排序