HDU 1272 小希的迷宫
来源:互联网 发布:趣味数学软件 编辑:程序博客网 时间:2024/06/18 16:22
还是并查集判断环的问题。。。这个题输入弄的很恶心。。。
#include<cstdio>#include<cstring>#include<iostream>#include<iomanip>#include<queue>#include<cmath>#include<stack>#include<map>#include<vector>#include<set>#include<algorithm>using namespace std;typedef long long LL;const int int_max = 0x07777777;const int int_min = 0x80000000;int root[110000];int vis[110000];int x,y;int find (int a){ while(root[a]!=a){ a = root[a]; } return a;}void combine (int a, int b){ int aa = find(a); int bb = find(b); if(aa!=bb){ root[bb] = aa; }}int main(int argc, const char * argv[]){ while(scanf("%d %d", &x, &y)!=EOF){ if(x==-1 && y==-1) break; if(x==0 && y==0){ cout << "Yes" << endl; continue; } int result= 0; int maxn = 0; for(int i = 0; i < 110000; i++) root[i] = i; memset(vis, 0, sizeof(vis)); while(x||y){ maxn = (maxn < (x < y ? y : x) ? (x < y ? y : x) : maxn); vis[x] = 1; vis[y] = 1; if(find(x)==find(y)) result = 1; else combine(x, y); cin >> x >> y; } int count = 0; for(int i = 1; i <= maxn; i++){ if(vis[i] && root[i]==i) count++; } if(result==1) cout << "No" << endl; else { if(count!=1) cout << "No" << endl; else cout << "Yes" << endl; } }}
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 小希的迷宫
- 桶式排序java实现
- 力矩限制器经典算法之一
- TRTOS的TQFS文件系统文件驱动层代…
- TQFS泛型文件管理层(第三层)驱动
- C++小实验之多态性理解
- HDU 1272 小希的迷宫
- 怎样查看端口占用情况
- 下一个语句
- VC++ CString
- 万能 float 闭合
- FZU 2122(KMP)
- OpenStack Heat总结之:Icehouse中通过Heat+Ceilometer实现Autoscaling
- ksfjldsjflasjsaljla
- JAVA反射机制