poj 1611 The Suspects
来源:互联网 发布:政务数据资源网 编辑:程序博客网 时间:2024/05/21 10:56
原题链接:http://poj.org/problem?id=1611
基础的并查集,开始时因为一个输入数据的地方写的有问题wa了好几遍,幸好后来发现了⊙﹏⊙b汗。。。
具体实现如下:
#include<stdio.h>#include<stdlib.h>#include<string.h>#define Max_N 30040int par[Max_N], rank[Max_N];void init(int n){int i;for (i = 0; i < n; i++){par[i] = i;rank[i] = 1;}}int find(int x){if (x == par[x]) return x;else return par[x] = find(par[x]);}void unite(int x, int y){x = find(x), y = find(y);if (x == y) return;if (rank[x] >= rank[y]){par[y] = x;rank[x] += rank[y];} else {par[x] = y;rank[y] += rank[x];}}int main(){#ifdef LOCALfreopen("in.txt", "r", stdin);freopen("out.txt", "w+", stdout);#endifint n, m, t, l, p, k;while (~scanf("%d %d", &n, &m)){if (0 == n && 0 == m) break;init(n);while (m--){scanf("%d %d", &t, &k);l = t;for (l = 1; l < t; l++){scanf("%d", &p);unite(k, p);}}printf("%d\n", rank[par[0]]);}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 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
- HDU 1297 Children’s Queue
- URAL 1294. Mars Satellites 几何
- IOS之地图和定位应用开发
- 第4章2节《MonkeyRunner源码剖析》ADB协议及服务: ADB服务SERVICES.TXT翻译参考(原创)
- Big "O"
- poj 1611 The Suspects
- Pig Latin关系操作
- ActiveMQ 基于JAAS的安全机制
- 一起学习 POI (使用 maven 构建)(1)-HelloWorld
- 修改MySql默认编码 分类: 转载 2011-12-05 12:17 13657人阅读 评论(0) 收藏 举报 mysqlcharacter数据库databasevariables数据库服务器
- JSP/Servlet 中的汉字编码问题
- 一起学习 POI (使用 maven 构建)(2)-为单元格数据设置格式
- java网络编程基础夯实06-TCP,UDP,HTTP,Socket简介
- Git的几种权限控制方案体验:gitosis(gitosis-ossxp-fork),gitolite