POJ1611 The Suspects
题目链接:点击打开链接
题目大意:有n个人,m个小组。一个人可能在多个小组,只要与0在一个小组的人都会可能被感染,这些人也可能感染别人and so on...现在让你求可能被感染的人数。
解题思路:显然的并查集求解,最后求一下谁和0的父亲节点是一样的就行了
代码:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<vector>
#define FAST ios::sync_with_stdio(false)
typedef long long ll;
const int mod = (int)1e9 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = (int)3e5 + 5;
using namespace std;int pre[maxn];int find(int x){ int r = x; while(pre[r] != r) r = pre[r]; int i = x, t; while(i != r){ t = pre[i]; pre[i] = r; i = t; } return r;
} void join(int x, int y){ int fx = find(x), fy = find(y); if(fx != fy) pre[fx] = fy;
} int main()
{int n, m;while(scanf("%d %d", &n, &m)){if(n == 0 && m == 0) break;for(int i = 0; i < n; i++) pre[i] = i;while(m--){int x, y; scanf("%d %d", &x, &y);for(int i = 1; i < x; i++){int t; scanf("%d", &t);join(t, y);}}int ans = 0;for(int i = 0; i < n; i++){if(find(i) == find(0)) ans++;}printf("%d\n", ans);}return 0;
}
over
POJ1611 The Suspects相关推荐
- SDU程序设计思维实践题目总结
题目来源及链接 题目名称及讲解博客链接 涉及算法 原题以及原题链接 第二周作业 Maze BFS POJ-3984 Pour water BFS POJ-1606 第二周实验 化学 模拟 codefo ...
- 北大ACM暑期培训课程目录
本文出自:http://blog.csdn.net/svitter 目录: 北大ACM暑期培训课程目录(二)(搜索) 北大ACM暑期培训课程目录(三)(图论) 北大ACM暑期培训课程目录(四)(计算几 ...
- B - The Suspects POJ - 1611
B - The Suspects POJ - 1611 基并查集 #include<iostream> #include<cstdio> #include<cstring ...
- POJ 1611 -The Suspects (并查集)
题目 Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, ...
- The Suspects//并查集
题目: The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 48312 Accepted: 2311 ...
- Poj 1611 The Suspects
Poj 1611 的传送门 ***The Suspects*** Description Severe acute respiratory syndrome (SARS), an atypical p ...
- POJ 1611 The Suspects (并查集)
The Suspects 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/B Description 严重急性呼吸系统综合症( S ...
- 并查集入门三连:HDU1213 POJ1611 POJ2236
HDU1213 http://acm.hdu.edu.cn/showproblem.php?pid=1213 问题描述 今天是伊格纳修斯的生日.他邀请了很多朋友.现在是晚餐时间.伊格纳修斯想知道他至少 ...
- (并查集)The Suspects
题目 Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recogni ...
最新文章
- 服务器端PHP多进程编程
- 【风控模型】神经网络DNN算法构建信用评分卡模型
- STM32的ADC采样与多通道ADC采样
- 字符转换属性text-tranform改变大小写
- 85.Mongoose指南 - Schema
- P4294-[WC2008]游览计划【斯坦纳树】
- android.mk 比较字变量,粉丝投稿 | 谈谈Android.mk
- 【Pytorch神经网络理论篇】 28 DGLGraph图的基本操作(缺一部分 明天补)
- Spring Cloud随记---分布式配置中心初探--一个单节点的配置中心
- getSelectionStart() doesn't work in android, is always 0
- python链家数据分析_练习—利用Python对链家网广州二手房进行数据分析
- python输入若干个数字求和
- 5750G GT540M显卡游戏蓝屏的终极解决方法!
- Python爬虫实现爬取糗事百科段子 (26行代码简单实现)
- 7个步骤!3分钟!轻松绘制简单好看的折线图!
- Windows socket之IOCP实例----IOCP开发驾照理论考试系统
- html文本只显示一行,如何让div中的文字只显示一行,多余的文字隐藏并加上省略号(超链接形式)...
- 3月15日 | 开启 ICLR 2023预讲会专场二
- #初等数学# 根式加减法法则
- R语言批量提取excel当中的数据
热门文章
- 儿童奶粉让孩子长高的关键 CBP为儿童长高加骨劲
- react-native 接QQ钱包支付的SDK
- Java毕业设计- 基于 SpringBoot 的智慧养老平台,附源码、教程
- 利用ENGINE替换OPENSSL中的加解密算法
- [附源码]JSP+ssm计算机毕业设计大学生工作室管理系统5465a【源码、数据库、LW、部署】
- 使用Active MQ在.net和java系统之间通信
- (附源码)pringboot冬奥会竞赛项目知识网站的设计与实现 毕业设计152337
- 暴风影音太恶心了 我用影音风暴
- Python对spss类型的sav文件读取操作
- Angular cdk 之 Overlay 源码分析