poj--2524
来源:互联网 发布:淘宝联盟加入购物车 编辑:程序博客网 时间:2024/05/21 09:56
一道简单的并查集
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int fa[55000];int find(int x){ return fa[x]==x?x:fa[x]=find(fa[x]);} void join(int x,int y){ int fx=find(x); int fy=find(y); if(fx!=fy) fa[fx]=fy;}int main(){ int n,m,i,j,Case=0; while(scanf("%d%d",&n,&m)&&n) { for(i=1;i<=n;i++) fa[i]=i; for(i=0;i<m;i++) { int k1,k2; scanf("%d%d",&k1,&k2); join(k1,k2); } int cnt=0; for(i=1;i<=n;i++) if(find(i)==i) cnt++; printf("Case %d: %d\n",++Case,cnt); } return 0;}
0 0
- poj 1988 &&poj 2524
- POJ 2524
- poj 2524
- poj 2524
- poj 2524
- poj 2524
- poj--2524
- poj-2524
- poj 2524
- poj 2524
- POJ 2524
- POJ 2524
- POJ 2524
- POJ 2524 Ubiquitous Religions
- POJ 2524 Ubiquitous Religions
- poj 2524 Ubiquitous Religions
- POJ 2524 Ubiquitous Religions
- POJ-2524 Ubiquitous Religions
- “石墨烯器件时代”还有多远?小电容带来大市场【www.shimoshop.com】
- Oracle 联机重做日志文件OnlineRedoLogFile
- Linux进阶——tar 解压缩命令
- Java如何通过WSDL文件来调用这些web service
- 32位win7系统下配置IIS遇到php-cgi.exe - FastCGI 进程意外退出问题的解决办法
- poj--2524
- hdu 4941 Magical Forest (map)
- UVA434 - Matty's Blocks
- poj-3225
- 一个简单的数字记忆训练软件介绍
- (14)Android监听时return 返回的false与true的区别
- lsnrctl 中 关于status 状态的说明
- LeetCode-Maximum Subarray
- axis2 jar包详解及缺少jar包错误分析