HDU-1213 并查集裸题
来源:互联网 发布:淘宝镜子自拍模特技巧 编辑:程序博客网 时间:2024/06/10 14:23
#include <cstdio>#include <cstring>#include <vector>#include <queue>#include <iostream>#include <cmath>#include <vector>#include <algorithm>#include <map>#include <set>using namespace std;typedef long long ll;#define DEBUGconst int maxn=110000+5,maxv=26,INF=0x3f3f3f3f,mod=100000000;int n,m,p[maxn];int find(int a){ return p[a]==a?a:find(p[a]);}int main(){#ifdef DEBUG freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);#endif int t; cin>>t; while(t--){ memset(p,0,sizeof(p)); cin>>n>>m; int a,b; for(int i=1;i<=n;i++) p[i]=i; while(m--){ cin>>a>>b; int pb=find(b),pa=find(a); if(pa!=pb) p[pa]=pb; } int ans=0; for(int i=1;i<=n;i++){ if(p[i]==i)ans++; } printf("%d\n",ans); }#ifdef DEBUG fclose(stdin); fclose(stdout);#endif return 0;}
阅读全文
0 0
- HDU-1213 并查集裸题
- HDU 1232 并查集裸题
- hdu 1213 并查集
- hdu 1213 并查集
- hdu 1213并查集
- HDU-1213并查集
- hdu 1213 并差集
- hdu 1213 并查集
- HDU 1213 并查集
- hdu 1213 并查集
- HDU 1213 并查集
- hdu 1213 并查集
- hdu 1213并查集
- hdu 1213 并查集
- HDU--1213并查集
- hdu 1213 并查集
- HDU 1213 并查集
- HDU 1213 并查集
- WIN10打开系统自带应用提示:XX出现问题 请与你的系统管理员联系
- 用JavaScript实现点击循环切换图片
- JDK报错:-bash: /usr/local/java/bin/java: No such file or directory
- Unity入门学习 //03_Game窗口
- Java程序员必看的书籍(附加下载地址)
- HDU-1213 并查集裸题
- (学习笔记)设计模式之单例模式
- YP2.6 Operations on Bits—Part II: Logical Operations(双语)
- STL(二十二)变易算法
- zoj3800线段树+离线
- 20170903WindowsPrj02_03_GDI
- MySQL知识整理(2)MySQL基本操作
- staruml2.8 破解
- stm32内存管理总结