zoj 1789 The Suspects
来源:互联网 发布:知其所以然论坛网址 编辑:程序博客网 时间:2024/06/03 14:40
并查集
把所有的联通起来,然后查找0所在的圈子包含的数量就可以了
#include <iostream>#include <cstdio>using namespace std;#define N 30010int parent[N];int treeId[N];inline void init(int i){ treeId[i] = -1;}int find(int x){ if (treeId[x]>=0) { return treeId[x]=find(treeId[x]); } return x;}int main(){ int n,m; while (scanf("%d %d",&n,&m)==2) { if (n==0&&m==0) break; for (int i=0;i<n;i++) { init(i); } while(m--) { int nm; scanf("%d",&nm); int father; int fatherParent =0; if(nm>0) { scanf("%d",&father); nm--; fatherParent= find(father); } while(nm--) { int tmp; scanf("%d",&tmp); int tmpParent = find(tmp); if(tmpParent!=fatherParent) { treeId[fatherParent] += treeId[tmpParent]; treeId[tmpParent] = fatherParent; } } } printf("%d\n",-treeId[find(0)]); } return 0;}
- ZOJ 1789 The Suspects
- zoj 1789 The Suspects
- zoj 1789 The Suspects
- zoj 1789 The Suspects
- zoj - 1789 - The Suspects
- zoj 1789 The Suspects
- zoj 1789The Suspects 并查集
- zoj 1789 || poj 1611 The Suspects(并查集)
- zoj 1789 The Suspects (并查集)
- zoj 1789||poj 1611 The Suspects(并查集,简单)
- POJ 1611 / ZOJ 1789: The Suspects - 并查集
- zoj The Suspects 并查集
- The Suspects
- The Suspects
- The Suspects
- The Suspects
- The Suspects
- The Suspects
- svn: Item is out of date
- 2112-Dynamic Rankings(超时)
- 对于REST中无状态(stateless)的一点认识
- Android之ListView
- DMX-SQL SERVER 数据挖掘简介一
- zoj 1789 The Suspects
- AndEngine 物理世界引擎 JNI 引入
- ImageView属性详解
- Windows文件操作的笔记和关键,MMClassify V2.0
- codeforces上解题感受
- Windows 8实例教程系列 - 开篇
- !!!Chapter 13 Copy Control
- UVa 11559 - Event Planning
- UVa 146 - ID Codes