HDU 1213 How Many Tables
来源:互联网 发布:加密狗软件安装 编辑:程序博客网 时间:2024/05/01 15:48
题意:
对于给出的人物关系,求出共有几波人。比如1认识2,2认识3,那么1,2,3就是同一波人。
思路:
就是并查集,没有坑点。
#include<iostream>#include<cstdio>using namespace std;int f[1100];int n,m,co;void mem(){for(int i=1;i<=n;i++)f[i]=i;} int find(int x){if(x!=f[x])f[x]=find(f[x]);return f[x];}void uni(int a,int b){a=find(a);b=find(b);if(a!=b){f[a]=b;}}int main(){int t;scanf("%d",&t);while(t--){scanf("%d%d",&n,&m);co=0;mem();int a,b;for(int i=0;i<m;i++){scanf("%d%d",&a,&b);uni(a,b);}for(int i=1;i<=n;i++)if(f[i]==i) co++;printf("%d\n",co);}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
- QueryRunner的实用方法及代码演示原理
- HDU
- BufferInputStream&BufferOutputStream
- “大宝剑”的用法:玩玩DEFCON后渗透工具Koadic
- DBC连接数据库经验技巧
- HDU 1213 How Many Tables
- C#_SOCKET通信
- JAVA assert关键字
- python数据结构之字典
- hibernate三
- Windows_VMware安装Linux(CentOS)虚拟机
- 原生的JSON解析
- Too many processes on hostname
- UVa-673 Parentheses Balance(栈模拟)