HDU 1232
来源:互联网 发布:python 字典转化列表 编辑:程序博客网 时间:2024/05/15 23:49
http://acm.hdu.edu.cn/showproblem.php?pid=1232
本人并查集专题:http://blog.csdn.net/fsafs168/article/details/7801010
/* * 并查集,直接标准写法秒过 * 思路:所谓畅通工程反向思维一下就是不畅通的有几块。 * 相应的建立的路就是:不畅通的块数-1 */#include <stdio.h>int father[1010];void ini(int n){ for(int i=0;i<=n;i++) father[i] = i;}int find(int x){ if(x != father[x]) return find(father[x]); return father[x];}void sert(int a, int b){ father[a] = b;}int main(){ int n,m,i,j; while(scanf("%d",&n)!=EOF&&n) { scanf("%d",&m); ini(n); for(i=0;i<m;i++) { int a,b; scanf("%d%d",&a,&b); a = find(a); //找根节点 b = find(b); //找根节点 if(a!=b) sert(a,b); } int sum = -1; //肯定是-1啦,因为至少有一块地方么 for(i=1;i<=n;i++) { if(i == find(i)) //有多少根节点 sum++; } printf("%d\n",sum); } return 0;}
- HDU 1232
- HDU 1232
- HDU 1232
- hdu 1232
- HDU 1232
- hdu 1232
- HDU 1232
- hdu 1232
- hdu 1232
- /* HDU 1232 */
- HDU 1232
- HDU 1232
- hdu 1232
- hdu 1232
- HDU 1232
- HDU 1232
- HDU 1232
- hdu 1232
- gcc 编译 expected unqualified-id before '(' token 问题
- MathType 在Word中的应用
- android 进程与线程 进程与进程 线程与线程通信问题
- 创建自己的搜索引擎
- android开发图片分辨率问题(drawable-(hdpi,mdpi,ldpi))
- HDU 1232
- 如何创建Hello rails !
- Windows XP 环境下安装 Apache HTTP Server 2.2.8
- 6.log4j.properties例子:同时指定多个appender
- 那些年,我们一起被“坑”的垃圾邮件
- 修改SQLServer2008 “sa” 的密码出错
- android sim 卡双卡双待
- poj 2488 A Knight's Journey
- (转)什么是套接字(Socket)?