并查集图冲突hdu1272
来源:互联网 发布:网络彩票平台代理招聘 编辑:程序博客网 时间:2024/05/15 23:48
还是属于并查集的变形
两个点只有一条路径连通
给出的两个点事先都是属于两个集合的
需要给出的着条边构成一个集合
算法复杂度还是挺高的
每个我都循环了100000次
set2数组没清空 wrong了一次
#include<cstdio>#include<algorithm>#include<cstring>using namespace std;int sett[100000 + 100];int set2[100000 + 100];int find2(int x){ while(x!=sett[x]) x=sett[x]; return x;}int merge2(int fx,int fy){ if(fx == fy) return 1; else if(fx > fy) sett[fx]=fy; else sett[fy] = fx; return 0;}int main(){ for(int i=1;i<=100000;i++) sett[i]=i; int x,y; int flag=1; while(scanf("%d%d",&x,&y)&&x!=-1&&y!=-1) { if(x==0&&y==0){ int countt=0; for(int i=1;i<=100000;i++) if(sett[i]==i&&set2[i]) countt++; if(countt >= 2) flag=0;// printf("countt %d\n",countt); if(flag) printf("Yes\n"); else printf("No\n"); flag = 1; for(int i=1;i<=100000;i++) sett[i]=i; memset(set2,0,sizeof(set2)); } else { set2[x]=1,set2[y]=1; int fx = find2(x); int fy = find2(y); if( merge2(fx,fy) ) { flag=0; } } } return 0;}
0 0
- 并查集图冲突hdu1272
- 【并查集】HDU1272
- HDU1272并查集
- 【并查集】hdu1272
- hdu1272(并查集)
- hdu1272并查集
- hdu1272 并查集
- HDU1272 并查集
- hdu1272 并查集
- HDU1272 并查集
- hdu1272 并查集
- hdu1272 并查集
- 并查集-hdu1272
- hdu1272(并查集)
- HDU1272(并查集)
- hdu1272(并查集)
- hdu1272
- hdu1272
- Bootstrap全局CSS样式之表格
- xocde 使用快捷键
- html5中多媒体的应用
- centos 6.6默认iptable规则
- html的文本元素总结
- 并查集图冲突hdu1272
- Python - 连续替换(replace)的正则表达式(re)
- 深入探讨Java 类加载器
- iOS 数据存储 归档普通对象 NSCoding NSKeyedArchiver
- Android环境搭建
- java连接MongoDB数据库
- 双端队列的应用
- PHP中的include和require
- Stange氧探头在S7-400模拟量处理