poj1611 The Suspects (并查集)
来源:互联网 发布:和讯网社会责任数据 编辑:程序博客网 时间:2024/05/22 08:12
题目链接:http://poj.org/problem?id=1611
//非常基础的并查集 可以参考http://www.cnblogs.com/cherish_yimi/archive/2009/10/11/1580839.html
#include<iostream>using namespace std;int f[30000],rank[30000];void makeset(int x){int i;for(i=0;i<x;i++)f[i]=i,rank[i]=0;}int findset(int x){if(x!=f[x])f[x]=findset(f[x]);return f[x];}void unionset(int a,int b){int fa=findset(a);int fb=findset(b);if(rank[fa]>rank[fb])f[fb]=fa;else{if(rank[fa]==rank[fb])rank[fb]++;f[fa]=fb;}}int main(){int n,m;while(cin>>n>>m,n||m){int cnt=1;//′ú±í?Dè?êyint i,j;makeset(n);for(i=0;i<m;i++){int t,a,b;cin>>t;cin>>a;for(j=1;j<t;j++){cin>>b;unionset(a,b);a=b;}}int st=findset(0);for(i=1;i<n;i++)if(st==findset(i))cnt++;cout<<cnt<<endl;}return 0;}
- POJ1611 The Suspects 并查集求解
- POJ1611 The Suspects 并查集
- poj1611 The Suspects (并查集)
- poj1611-The Suspects--并查集
- poj1611 The Suspects(并查集)
- POJ1611 The Suspects (并查集)
- 并查集 poj1611 The Suspects
- POJ1611 The Suspects 并查集
- poj1611 The Suspects(基础并查集)
- poj1611 The Suspects 并查集
- POJ1611:The Suspects【并查集】
- poj1611 The suspects 并查集
- 【并查集】:poj1611,The Suspects
- POJ1611 The Suspects(并查集)
- poj1611 the-suspects 并查集
- POj1611:The Suspects(并查集)
- POJ1611 The Suspects 种类并查集
- POJ1611 The Suspects(并查集)
- 抓过google的数据没?
- C#中五种跳转语句
- 内部创业的五种死因
- jquery uploadify在谷歌浏和火狐下无法上传的解决方案(.Net版)
- struts2中的OGNL表达式语言
- poj1611 The Suspects (并查集)
- SQL语句中把多条记录同一字段的值连接成一个字符串显示结果集(sql stuff)
- 转载几个牛人的牛语录:有关FPGA和DSP和ARM的。
- android中使用adb shell命令kill掉应用程序
- 程式語言的特性本質(四)往數學領域抽象化的函數程式設計
- WIN32 实现OPenGL显示源码
- Oracle WIP Backflush
- oracle主键和外键
- linux常用svn命令