并查集 水题
来源:互联网 发布:淘宝怎么玩赚钱 编辑:程序博客网 时间:2024/06/01 09:24
题目链接
#include <iostream>#include<stdio.h>#include<math.h>#include<algorithm>#include<string.h>#include<stack>#include<queue>#include<vector>#include<stdlib.h>using namespace std;const int INF =2100000000;int pre[1010];void Init(int n){ for(int i=0;i<=n;i++) pre[i]=i;}int finds(int x){ return pre[x]==x?x:pre[x]=finds(pre[x]);}void jion(int x,int y){ int fx=finds(x); int fy=finds(y); pre[fy]=fx;}int main(){ int n_case; scanf("%d",&n_case); while(n_case--) { int people,contect,i; scanf("%d %d",&people,&contect); Init(people); for(i=1;i<=contect;i++) { int x,y; scanf("%d%d",&x,&y); jion(x,y); } int ans=0; for(i=1;i<=people;i++) { if(pre[i]==i) ans++; } printf("%d\n",ans); } return 0;}
0 0
- 并查集 水题
- 并查集-水题
- HDU3938 并查集 并查集
- 并查集(集并查)
- HDU1232 并查集<并>
- X-Plosives +uvalive+并查集+水题
- HDOJ-----2120并查集(水题)
- 并查集
- 数据结构-并查集
- 并查集
- 并查集!
- 并查集
- 并查集
- 并查集
- 并查集
- 并查集总结
- 并查集学习
- 并查集
- 虚幻4 Function Library
- 剑指offer-面试题3.二维数组中的查找
- AlertDialog 自定义布局点击按钮消失方法
- DE1-SOC开发之路--安装ubantu系统
- grep操作
- 并查集 水题
- java 访问权限修饰符理解
- JavaScript之调用函数的方式
- 为什么突然之间有了写博客的想法
- 数组定和元素求解探究
- 【LeetCode】53. Maximum Subarray
- 循环冗余检验 (CRC) 算法原理
- /proc/iomem和/proc/ioports
- 关于#ifndef,#define,#end的说明