B - The Suspects POJ - 1611

基并查集

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 3e4+100;
int n, m;
int fa[maxn], cnt[maxn];void init() {memset(cnt, 0, sizeof(cnt));for(int i = 0; i < n; i++) fa[i] = i, cnt[i] = 1;
}int find(int x) {if(fa[x] == x) return x;else return fa[x] = find(fa[x]);
}void Union(int x, int y) {int xx = find(x), yy = find(y);if(xx == yy) return ;if(cnt[xx] > cnt[yy]) swap(xx, yy);fa[xx] = yy; cnt[yy] += cnt[xx];return ;
}int main() {//  freopen("test.in", "r", stdin);while(~scanf("%d%d", &n ,&m) && n+m) {init();for(int i = 0; i < m; i++) {int k; scanf("%d", &k);int s, tmp, ss;for(int i = 1; i <= k; i++) {if(i == 1) {scanf("%d", &s);}else {scanf("%d", &tmp);if(find(s) != find(tmp)) Union(s, tmp);};}}
//      for(int i = 0; i < n; i++) printf("cnt[%d]=%d\n", i, cnt[i]);printf("%d\n", cnt[find(0)]);}return 0;
}

B - The Suspects POJ - 1611相关推荐

  1. Poj 1611 The Suspects

    Poj 1611 的传送门 ***The Suspects*** Description Severe acute respiratory syndrome (SARS), an atypical p ...

  2. POJ - 1611 The Suspects

    题目链接:1611 -- The Suspects 问题描述 思路 简单并查集 代码 #include <cstdio> #include <cstring> #include ...

  3. POJ 1611 -The Suspects (并查集)

    题目 Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, ...

  4. POJ 1611 The Suspects (并查集)

    文章作者:ktyanny 文章来源:ktyanny 转载请注明,谢谢合作. ktyanny:a的第一道并查集. 题目描述: 有很多组学生,在同一个组的学生经常会接触,也会有新的同学的加入.但是SARS ...

  5. POJ 1611 The Suspects (并查集)

    The Suspects 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/B Description 严重急性呼吸系统综合症( S ...

  6. POJ 1611 The Suspects 并查集

    The Suspects Time Limit:1000MS     Memory Limit:20000KB     64bit IO Format:%lld & %llu Descript ...

  7. POJ 1611 The Suspects

    题意:说有n个学生,m个小组,然后0号童鞋感染了sars,跟感染者一组的也认为是感染者了,问一共多少感染者. 解法:并查集-- 代码: #include<stdio.h> #include ...

  8. poj 1611 The Suspects // hoj 1564 The Suspects 并查集

    /* 题目: 是说学生0怀疑有SARS病,跟他接触过的俱乐部的所有人以及他接触过的人再与别人接触, 都有可能有SARS病,要你求出给出的所有俱乐部人的名单,要你求出所有的嫌疑犯... 分析: 用并查集 ...

  9. POJ 1611 嫌疑犯

    目录 题目链接 大意 思路 代码 题目链接 http://poj.org/problem?id=1611 大意 有∞∞∞组数据,每组数据告诉你n个人,分为m组,每组的人都会互相传染,假设0" ...

最新文章

  1. Django博客系统注册(图形验证码接口设计和定义)
  2. 2017年秋季个人阅读计划
  3. 请求--拦截器--action经过
  4. Html5 Canvas斗地主游戏
  5. python基础编码规范_Python语言的基本语法和编码规范.doc
  6. 找出不是两个数组共有的元素
  7. charles抓包https/模拟弱网/设置断点/修改接口请求值或返回值/压测
  8. pytorch基础教程2
  9. talentcentral测评结果_人才测评报告
  10. 微信小程序 flex:1表示什么
  11. html js中点击事件的三种方法
  12. 电子智能Siri与Simsimi评测(上)
  13. pythonmd5解密代码_python写一个md5解密器示例,pythonmd5解密器
  14. Hadoop+Spark 之旅—脚踏实地、仰望星空(教程目录)
  15. 一行代码能实现什么丧心病狂的功能?
  16. 月入2万的10个小生意项目
  17. 外卖订单量预测异常报警模型实践
  18. 服务器被DDoS攻击,怎么破?
  19. 鹏城实验室云主机申请以及Xshell远程连接教程
  20. C语言之简单版本银行储蓄系统4(结构体版本)

热门文章

  1. 在OpenCV中基于深度学习的边缘检测
  2. 自动驾驶高清地图问题的研究
  3. 链表问题8——将单向链表按某值划分成左边小、中间相等、右边大的形式(初阶)
  4. MATH6005 Final Assignment MATH6005 2018-19
  5. VirtualBox上装CentOS5.8网络不通问题
  6. Python学习笔记(八)
  7. Linux SWAP分区占用率高,刷新SWAP分区方法
  8. 关于mongodb ,redis,memcache之间见不乱理还乱的关系和作用
  9. Cocos2d-x手机游戏开发行业背景分析
  10. 写出一个超强的lighttpd模块