poj 1611 The Suspects(并查集)
来源:互联网 发布:java获取不到cookie 编辑:程序博客网 时间:2024/06/03 21:42
#include<iostream>#include<stdio.h>#include<string.h>using namespace std;#define MAXN 30005int fa[MAXN];int set_find(int d){ if(fa[d]<0)return d; return fa[d]=set_find(fa[d]);}void set_join(int x,int y){ x=set_find(x); y=set_find(y); if(x!=y)fa[x]=y;}int main(){ int n,m,k; int x,y; int fa0;//节点0的父节点 int sum;// while(~scanf("%d%d",&n,&m)) { if(n==0&&m==0)break; memset(fa,-1,sizeof(fa)); for(int i=0; i<m; ++i) { scanf("%d",&k); scanf("%d",&x); for(int j=1; j<k; ++j) { scanf("%d",&y); set_join(x,y); } } fa0=set_find(0); sum=0; for(int i=0; i<n; ++i) { if(set_find(i)==fa0) { ++sum; } } printf("%d\n",sum); } return 0;}
0 0
- POJ 1611 The Suspects(并查集)
- poj 1611 The Suspects 并查集
- POJ 1611 The Suspects 并查集
- poj 1611 The Suspects(并查集)
- POJ 1611 The Suspects 并查集
- POJ--1611--The Suspects【并查集】
- poj 1611-The Suspects:并查集
- POJ--1611 -- The Suspects [并查集]
- poj 1611 - The Suspects(并查集)
- poj 1611The Suspects 并查集
- poj 1611 The Suspects 并查集
- [并查集]POJ 1611 The Suspects
- poj 1611 The Suspects --- 并查集
- POJ 1611 The Suspects (并查集)
- POJ 1611 The Suspects(并查集)
- POJ 1611--The Suspects 并查集
- POJ 1611 The Suspects 并查集
- poj 1611 The Suspects(并查集)
- tableview或者ScrollView看不到边界以外的内容
- java学习—day_6
- Centos下:/usr/bin/ld: cannot find -lXext
- float类型在值传递过程中出现的问题
- 项目管理十大知识范围
- poj 1611 The Suspects(并查集)
- 数据结构与算法学习
- 系统学习机器学习之参数方法(三)
- 网站开发进阶(二十九)HTML特殊转义字符
- 深度学习与计算机视觉系列(4)_最优化与随机梯度下降\数据预处理,正则化与损失函数
- setbuf函数使用注意事项
- Oracle In-Memory 行列双格式
- 二叉树创建-前言
- 开发中的Bug、异常功能调试思路