http://acm.hdu.edu.cn/showproblem.php?pid=1232&&并查集应用
来源:互联网 发布:淘宝上欧货是什么意思 编辑:程序博客网 时间:2024/06/10 22:50
水题进行时。。。。加油(*^__^*) 嘻嘻……。。。
#include<iostream>#include<string.h>#include<algorithm>#include<limits.h>#define N 1005#define FOR(i,s,t) for(int i=(s);i<=t;++i)using namespace std;int n,m,tot;int father[N];void make_set(){ FOR(i,1,n) father[i]=i; tot=n; }int find_set(int a){ while(a!=father[a]) a=father[a]; return a; } void Union(int a,int b) { int x=find_set(a); int y=find_set(b); if(x!=y) { father[y]=x; tot--; } } int main() { while(cin>>n&&n) { cin>>m; make_set(); FOR(i,1,m) { int a,b; cin>>a>>b; Union(a,b); } cout<<tot-1<<endl; } return 0; }
- http://acm.hdu.edu.cn/showproblem.php?pid=1232&&并查集应用
- 并查集 小希的迷宫http://acm.hdu.edu.cn/showproblem.php?pid=1272
- http://acm.hdu.edu.cn/showproblem.php?pid=1005
- http://acm.hdu.edu.cn/showproblem.php?pid=1333
- http://acm.hdu.edu.cn/showproblem.php?pid=2710
- http://acm.hdu.edu.cn/showproblem.php?pid=2866
- http://acm.hdu.edu.cn/showproblem.php?pid=1041
- http://acm.hdu.edu.cn/showproblem.php?pid=1719
- http://acm.hdu.edu.cn/showproblem.php?pid=2136
- http://acm.hdu.edu.cn/showproblem.php?pid=1166
- http://acm.hdu.edu.cn/showproblem.php?pid=3519
- http://acm.hdu.edu.cn/showproblem.php?pid=2446
- http://acm.hdu.edu.cn/showproblem.php?pid=1709
- http://acm.hdu.edu.cn/showproblem.php?pid=1874
- http://acm.hdu.edu.cn/showproblem.php?pid=1863
- http://acm.hdu.edu.cn/showproblem.php?pid=1879
- http://acm.hdu.edu.cn/showproblem.php?pid=1875
- http://acm.hdu.edu.cn/showproblem.php?pid=1102
- Delphi 封装动态库调用
- 陕北行记之小镇印象
- VC++使用静态库,msvcrt.lib连接错误
- ASP 连接数据库方法总结
- 不要忘了 父母的老手更盼望着我们去牵
- http://acm.hdu.edu.cn/showproblem.php?pid=1232&&并查集应用
- Opencv中人体检测
- (原博客转移)诺基亚手机成板砖无法开机后,强刷修复手机系统的方法!本人亲测
- 如何联机调试和发布程序(99$)
- GridView中BoundField与TemplateField的区别
- android中改变字体
- HPS项目总结
- debian Squeeze 4965AGN无线安装以及debian的使用配置,VPN安装.
- DevExpress控件之GridControl控件