HDU 1272(并查集)
来源:互联网 发布:十分钟看懂时序数据库 编辑:程序博客网 时间:2024/05/06 03:53
#include<stdio.h>#include<stdlib.h>#include<algorithm>#include<math.h>#include<string.h>#include<queue>#include<vector>#include<map>using namespace std;#define rep(i,n) for(int (i)=1;(i)<=(int)(n);++(i))const int MAXN=100005;int from[MAXN],to[MAXN];int father[MAXN];int Find(int x){ if(x==father[x]) return x; return father[x]=Find(father[x]);}int main(){ //freopen("test.txt","r",stdin); int a,b; int n=0,m=0,cnt=0,ans=0; while(scanf("%d%d",&a,&b)&&(a!=-1&&b!=-1)) { father[a]=a,father[b]=b; if(a&&b) { from[++m]=a;to[m]=b; continue; } rep(i,MAXN) if(father[i]==i)n++; rep(i,m) { int ff=Find(from[i]),ft=Find(to[i]); if(ff==ft) {ans=1;break;}<span style="white-space:pre"></span> else { father[ff]=ft; cnt++; } } if(!ans&&(cnt==n-1||n==0)) printf("Yes\n"); else printf("No\n"); memset(father,0,sizeof(father)); n=0,m=0,cnt=0,ans=0; } 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
- java实现定时任务的基础方法
- Python_多线程初解(threading模块)
- 一个人的旅行(HDU2066)
- 文章标题
- Android Studio 应用签名
- HDU 1272(并查集)
- 命令模式
- flex上下固定中间滚动布局
- win7 系统盘下AppData文件夹中Local和Roaming分别有什么作用?
- NSNumberFormatter的使用
- OJ-----计算字符个数
- HDU 5823 color II(状压DP)
- List排序
- Iterator设计模式,探究STL中迭代器的实现原理