hdu 1213 并查集
来源:互联网 发布:安卓登录注册界面源码 编辑:程序博客网 时间:2024/05/14 15:57
并查集基本题。
#include<iostream>#include<cstring>#include<cstdlib>#include<cstdio>#include<cmath>#include<string>#include<map>#include<set>#include<algorithm>#include<vector>#include<queue>#include<stack>#include<sstream>#define LL long long#define OJ_DEBUG 0#define READ_FILE 0using namespace std;const int NN_MAX = 1000+10;const int MM_MAX = 100010;const int INF = 0x3fffffff;/**********************************************************/int p[NN_MAX];/**********************************************************/int min_2 (int x,int y) {return x<y?x:y;}int max_2 (int x,int y) {return x>y?x:y;}void swap (int& a, int& b){a^=b;b^=a;a^=b;}int find (int i){return i==p[i]?i:p[i]=find (p[i]);}void merge (int i,int j){ int x=find (i); int y=find (j); if (x!=y)p[y]=x;}/**********************************************************/int main(){ if (READ_FILE) freopen ("in.txt","r",stdin); int tt,n,m; scanf ("%d",&tt); while (tt--) {scanf ("%d %d",&n,&m);int a,b;for (int i=0;i<=n;i++) p[i]=i;for (int i=0;i<m;i++){ scanf ("%d %d",&a,&b); merge (a,b);}int cnt=0;for (int i=1;i<=n;i++) if (i==find (i))cnt++;printf ("%d\n",cnt); } return 0;}
0 0
- 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 (并查集)
- hdu 1213 并查集
- hdu 1213 (并查集)
- Num 22 : NYOJ : 0055 懒省事的小明 [ 优先队列 ]
- jquery全选
- 【Launcher 教程】从 URL Schemes 入门到用 Launcher 调用各效率软件
- Cat VS Dog
- exploit - Sudo <=1.8.14 - Unauthorized Privilege
- hdu 1213 并查集
- 句柄类
- css文字溢出显示省略号
- var_dump展示不全
- 如何取消文件的关联
- 虚函数和纯虚函数的区别
- ER图简明教程
- Android lint优化 Improving Your Code with lint
- CodeMirror动态显示