HDU1213
来源:互联网 发布:高尔夫gte数据 编辑:程序博客网 时间:2024/05/14 19:53
并查集超级水题
#include<iostream>#include<queue>#include<stack>#include<cstdlib>#include<memory.h>using namespace std;int map[1001];int book[1001];int gen(int x){ while(x!=map[x]) { x=map[x]; } return x;}void hebing(int a,int b){ int a1=gen(a); int b1=gen(b); if(a1!=b1) { map[a1]=b1; }}int main(){ int T; cin>>T; while(T--) { memset(book,0,sizeof(book)); int n,m; cin>>n>>m; for(int a=1;a<=n;a++)map[a]=a; for(int sd=1;sd<=m;sd++) { int s,d; cin>>s>>d; hebing(s,d); } for(int a=1;a<=n;a++) { book[gen(a)]=1; } int sum=0; for(int a=1;a<=n;a++) { if(book[a]==1)sum++; } cout<<sum<<endl; } return 0;}
0 0
- hdu1213
- HDU1213
- HDU1213
- hdu1213
- hdu1213
- HDU1213
- hdu1213
- hdu1213
- hdu1213
- HDU1213
- hdu1213
- hdu1213+hdu1232
- HDU1213:How Many Tables
- HDU1213--How Many Tables
- hdu1213-How Many Tables
- hdu1213 How Many Tables
- hdu1213 How Many Tables
- HDU1213 How Many Tables
- 黑客技术,
- theano卷积神经网络实现
- UWP项目中加载svg矢量图
- HDU 5726 GCD
- http协议要点二
- HDU1213
- Spring源码解析(一) Spring事务控制之Hibernate
- [leetcode] 238. Product of Array Except Self
- 【Android基础知识】Android多线程下载
- ajax请求json数据
- 初识DataFrames
- canvas arcTo()用法详解
- 【打CF,学算法——一星级】Codeforces 699A Launch of Collider (水题)
- mac添加android的adb等工具到环境变量