hdu-1213 how many tables
来源:互联网 发布:红警全图作弊器软件 编辑:程序博客网 时间:2024/05/20 09:22
http://acm.hdu.edu.cn/showproblem.php?pid=1213
并查集
#include<stdio.h>#include<iostream>#include<math.h>#include<stdlib.h>#include<ctype.h>#include<algorithm>#include<vector>#include<string.h>#include<queue>#include<stack>#include<set>#include<map>#include<sstream>#include<time.h>#include<utility> #include<malloc.h> #include<stdexcept>using namespace std;int n, m, t;int p[10000];int b[10000];int find(int x){if (x == p[x])return x;elsereturn find(p[x]);}int fa, fb;void un(int x, int y){fa = find(p[x]);fb = find(p[y]);if (fa != fb){if (fa>fb)p[fa] = fb;elsep[fb] = fa;}}int main(){scanf("%d",&t);while (t--){scanf("%d%d", &n, &m);for (int i = 1; i <= n; i++)p[i] = i;int sum = 0;int a, b;for (int i = 1; i <= m; i++){scanf("%d%d", &a, &b);un(a, b);}for (int i = 1; i <= n; i++){if (p[i] == i)sum++;}printf("%d\n", sum);}return 0;}
0 0
- hdu 1213 how many tables
- hdu 1213 How Many Tables
- hdu 1213 How Many Tables
- HDU 1213 How Many Tables
- hdu 1213 How Many Tables
- HDU 1213 How Many Tables
- hdu 1213 How Many Tables
- Hdu 1213 How Many Tables
- hdu 1213 How Many Tables
- hdu 1213 How Many Tables
- HDU 1213 how many tables
- hdu 1213 How Many Tables
- hdu 1213how many tables
- hdu 1213 How Many Tables
- Hdu 1213 - How Many Tables
- HDU 1213 How Many Tables
- HDU 1213 How Many Tables
- hdu 1213 How Many Tables
- 简单理解jQuery中$.getJSON、$.get、$.post、$.ajax用法
- cursor
- 二分查找(递归与非递归方式)
- 注释与变量
- 开源ETL工具--Kettle的简易使用实例
- hdu-1213 how many tables
- [leetcode 75] Sort Colors
- android之service(我也是学习别人的)
- PostgreSql盲注相关代码
- 利用sqlserver查询分析器,批量插入数据
- Java正则表达式
- container with most water
- Java web----Response
- android之Bundle