How Many Tables(HDU1213)(入门)
来源:互联网 发布:淘宝上办签证被骗了 编辑:程序博客网 时间:2024/06/05 20:50
どこでもドア:http://acm.hdu.edu.cn/showproblem.php?pid=1213
N个编号,M个连通
输出有几个集合
CODE:
#include<iostream>#include<cstdio>#include<algorithm>#include<cmath>using namespace std;const int MAX=100005;int ma[MAX];int sum;int Find(int x){ return x==ma[x]? x: ma[x]=Find(ma[x]);}void mix(int x,int y){ x=Find(x); y=Find(y); if(x!=y) ma[y]=x;}int main(){ int t,x,y,n,m; scanf("%d",&t); while(t--) { sum=0; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) ma[i]=i; while(m--) { scanf("%d%d",&x,&y); mix(x,y); } for(int i=1;i<=n;i++) if(ma[i]==i) sum++; cout<<sum<<endl; } return 0;}
0 0
- How Many Tables(HDU1213)(入门)
- HDU1213:How Many Tables
- HDU1213--How Many Tables
- hdu1213-How Many Tables
- hdu1213 How Many Tables
- hdu1213 How Many Tables
- HDU1213 How Many Tables
- hdu1213 How Many Tables
- How Many Tables hdu1213
- HDU1213---How Many Tables
- hdu1213 How Many Tables
- hdu1213 How Many Tables
- HDU1213 How Many Tables
- hdu1213 How Many Tables
- [hdu1213] How Many Tables
- HDU1213-How Many Tables
- hdu1213 How Many Tables
- HDU1213 How Many Tables
- 关于字符串以及数组的操作
- HDU1392
- html 03 浮动布局以及清除浮动
- 【译】4个你需要知道的Asset Catalog的秘密
- 05node.js事件驱动程序
- How Many Tables(HDU1213)(入门)
- ContentProvider中常用的常量及字段
- POJ 3600 Subimage Recognition 搜索
- Hadoop安装(一)
- PHP 远程文件包含的介绍和代码防御
- angular自定义的tab切换
- 多线程(一)
- JAVA设计模式-责任链模式
- Python学习 自定义函数