【POJ 1611】【并查集】The Suspects
来源:互联网 发布:英雄杀探宝固定数据 编辑:程序博客网 时间:2024/06/06 12:36
水水的并查集,上学期为什么我会半天A不了,好神奇的说;
#include "iostream"using namespace std;#define Max 300010int f[Max],num[Max];//num是关键。void init();int find(int x);void join(int x,int y);int main(int argc, char const *argv[]){ int n,m,a,father,son; while(~scanf("%d %d",&n,&m) && (n+m)) { init(); for (int i = 0; i < m; ++i) { scanf("%d",&a); scanf("%d",&father); for (int j = 1; j < a; ++j) { scanf("%d",&son); join(father,son); } } printf("%d\n",num[find(0)]);//找到0所在的集合 } return 0;}void init(){ for (int i = 0; i < n; ++i) { f[i]=i; num[i]=1; }}int find(int x){ if(x==f[x]) return x; return f[x]=find(f[x]);}void join(int x,int y){ x=find(x); y=find(y); if(x!=y) { f[y]=x; num[x]+=num[y]; }}
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(并查集)
- Java中引用类型变量的转换
- “框架”与“库”在概念上的差异分析
- 剑指offer系列之8:跳台阶问题
- Leetcode no. 201
- 机器学习之SVM分类
- 【POJ 1611】【并查集】The Suspects
- Android Studio 入门
- Android应用程序包解析过程浅析
- 《机器学习实战》使用Apriori算法和FP-growth算法进行关联分析(Python版)
- 设计模式-11-组合模式
- 多线程同步与死锁深入分析
- ubuntu中用python把文件的编码改成utf8
- Jdk的安装及配置
- 关于重建二叉树问题已经二叉树前序排列和中序排列求二叉树