zoukankan
html css js c++ java
HDU1272 小希的迷宫 并查集
/*并查集的应用,注意点的个数为0的时候,注意输入*/ #include <iostream> #include "UFS.h" using namespace std; UFS ufs; bool flag[MAXN]={0}, f; int cnt_e, cnt_v; void init(); int main() { int n,m; init(); while(cin>>n>>m) { if(m==-1&&n==-1)return 0; if(m==0&&n==0) { getchar();getchar(); /*条件:1.ufs不冲突2.v=e+1(v=0时例外)*/ if(f) cout<<"No"<<endl; else if(cnt_v==0)cout<<"Yes"<<endl; else if(cnt_v!=cnt_e+1)cout<<"No"<<endl; else cout<<"Yes"<<endl; init(); } else { if(flag[m] == 0) { flag[m] = 1; cnt_v++; } if(flag[n] == 0) { flag[n] = 1; cnt_v++; } m = ufs.Find(m); n = ufs.Find(n); if(m==n) f=1; else { ufs.Union(m, n); cnt_e++; } } } return 0; } void init() { ufs.clear(); memset(flag, 0, sizeof(flag)); f = 0; cnt_v = 0; cnt_e = 0; }
查看全文
相关阅读:
372. Super Pow
224. Basic Calculator + 227. Basic Calculator II
263. Ugly Number + 264. Ugly Number II + 313. Super Ugly Number
169. Majority Element
225. Implement Stack using Queues + 232. Implement Queue using Stacks
551. Student Attendance Record I + Student Attendance Record II
765. Couples Holding Hands
547. Friend Circles
535. Encode and Decode TinyURL
87. Scramble String
原文地址:https://www.cnblogs.com/windmissing/p/2559866.html
最新文章
Hash表模板
POJ 3243 Clever Y | BSGS算法完全版
POJ2417 Discrete Logging | A,C互质的bsgs算法
BZOJ 1876 [SDOI2009] SuperGcd | PY好题
POJ 2891 Strange Way to Express Integers | exGcd解同余方程组
POJ 1006 Biorhythms | 中国剩余定理
POJ 2115 C-Looooops | exgcd
POJ 2142 The balance | EXGCD
数论学习总结 | 各种模板
POJ 1061 青蛙的约会 | 同余方程和exGcd
热门文章
POJ 3090 Visible Lattice Points | 其实是欧拉函数
POJ 3421 X-factor Chains | 数论
洛谷树剖模板题 P3384 | 树链剖分
POJ 2243 [SDOI2011]染色 | 树链剖分+线段树
BZOJ 1036 [ZJOI2008]树的统计Count | 树链剖分模板
POJ 3264 Balanced Lineup | st表
POJ 1990 MooFest | 树状数组
POJ 2352 Stars | 树状数组
Codeforces 498D Traffic Jams in the Land | 线段树
496. Next Greater Element I + 503. Next Greater Element II + 556. Next Greater Element III
Copyright © 2011-2022 走看看