Educational Codeforces Round 65 (Rated for Div. 2) C. News Distribution
链接:https://codeforces.com/contest/1167/problem/C
题意:
In some social network, there are nn users communicating with each other in mm groups of friends. Let's analyze the process of distributing some news between users.
Initially, some user xx receives the news from some source. Then he or she sends the news to his or her friends (two users are friends if there is at least one group such that both of them belong to this group). Friends continue sending the news to their friends, and so on. The process ends when there is no pair of friends such that one of them knows the news, and another one doesn't know.
For each user xx you have to determine what is the number of users that will know the news if initially only user xx starts distributing it.
思路:
裸并查集
代码:
#include <bits/stdc++.h>
using namespace std; const int MAXN = 5e5+10; int Fa[MAXN];
int Dis[MAXN]; int GetF(int x)
{
if (Fa[x] == x)
return Fa[x];
Fa[x] = GetF(Fa[x]);
return Fa[x];
} int main()
{
int n, m;
cin >> n >> m;
for (int i = 1;i <= n;i++)
Fa[i] = i;
int num, p;
for (int i = 1;i <= m;i++)
{
cin >> num;
int head;
if (num > 0)
{
cin >> p;
head = GetF(p);
num--;
}
while (num--)
{
cin >> p;
int h = GetF(p);
Fa[h] = head;
}
}
for (int i = 1;i <= n;i++)
{
int head = GetF(i);
Dis[head]++;
}
for (int i = 1;i <= n;i++)
{
int head = GetF(i);
cout << Dis[head] << ' ' ;
}
cout << endl; return 0;
}
Educational Codeforces Round 65 (Rated for Div. 2) C. News Distribution的更多相关文章
- Educational Codeforces Round 65 (Rated for Div. 2)题解
Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...
- Educational Codeforces Round 65 (Rated for Div. 2) D. Bicolored RBS
链接:https://codeforces.com/contest/1167/problem/D 题意: A string is called bracket sequence if it does ...
- Educational Codeforces Round 65 (Rated for Div. 2) B. Lost Numbers
链接:https://codeforces.com/contest/1167/problem/B 题意: This is an interactive problem. Remember to flu ...
- Educational Codeforces Round 65 (Rated for Div. 2) A. Telephone Number
链接:https://codeforces.com/contest/1167/problem/A 题意: A telephone number is a sequence of exactly 11 ...
- Educational Codeforces Round 65 (Rated for Div. 2)B. Lost Numbers(交互)
This is an interactive problem. Remember to flush your output while communicating with the testing p ...
- [ Educational Codeforces Round 65 (Rated for Div. 2)][二分]
https://codeforc.es/contest/1167/problem/E E. Range Deleting time limit per test 2 seconds memory li ...
- Educational Codeforces Round 65 (Rated for Div. 2)
A:签到. #include<bits/stdc++.h> using namespace std; #define ll long long #define inf 1000000010 ...
- Educational Codeforces Round 65 (Rated for Div. 2) E. Range Deleting(思维+coding)
传送门 参考资料: [1]:https://blog.csdn.net/weixin_43262291/article/details/90271693 题意: 给你一个包含 n 个数的序列 a,并且 ...
- Educational Codeforces Round 65 (Rated for Div. 2)(ACD)B是交互题,不怎么会
A. Telephone Number A telephone number is a sequence of exactly 11 digits, where the first digit is ...
随机推荐
- less的安装使用和入门实践
1.简介 LESSCSS是一种动态样式语言,属于CSS预处理语言的一种,它使用类似CSS的语法,为CSS的赋予了动态语言的特性,如变量.继承.运算.函数等,更方便CSS的编写和维护. LESSCSS可 ...
- h5打电话发短信写邮件怎么实现
// 一.打电话<a href="tel:0755-10086">打电话给:0755-10086</a> // 二.发短信,winphone系统无效< ...
- Linus Torvalds: 成功的项目源于99%的汗水与1%的创新
2017年2月15日,在加利福尼亚州的开源领袖峰会上,由Linux基金会执行董事Jim Zemlin进行的一次采访中,Torvalds讨论了他如何管理Linux内核的开发以及他对工作的态度. Linu ...
- blog集合
godiscoder的技术blog 一个不错的技术架构设计blog MySQLOPS 数据库与运维自动化技术分享 stone的技术blog 陈皓专栏 风雪涟漪的技术blog 华为首席科学家 张宴技术b ...
- physoft.net网站暂停 www.physoft.cn 正式开通 (菲烁科技, physoft)
physoft.net原本计划以开源代码为主体,由于各种原因代码未能开源.基于这些代码,physoft成立了 菲烁(重庆)科技有限公司 ( www.physoft.cn) ,专注于工业级双目视觉测量, ...
- 01PS基础
通道:记录颜色信息 alpha通道:主要用来记录选取 画笔颜色模式:会保留纹理,不要直接在原图上画,可以新建一个层,然后变成颜色模式 调整色阶(ctrl + l)的三种方式:1.输入:修改前 > ...
- QT(1)介绍
Qt官网 Qt官网:https://www.qt.io Qt下载:http://www.qt.io/download Qt所有下载:http://download.qt.io/archive/qt Q ...
- 洛谷 P5061 秘密任务 —— 二分图
题目:https://www.luogu.org/problemnew/show/P5061 首先,“配合默契”就是连边的意思: 但发现答案不好统计,因为有连边的两个点可以分在一组,也可以不分在一组: ...
- 什么是BI(Business Intelligence)
一.BI的定义 BI是Business Intelligence的英文缩写,中文解释为商务智能,用来帮助企业更好地利用数据提高决策质量的技术集合,是从大量的数据中钻取信息与知识的过程.简单讲就是业务. ...
- 7.22实习培训日志-JSP Servlet
周末总结 今天下午在学习servlet,想自己做一个简单的例子,于是用idea新建一个maven项目,为了后文叙述方便,我们取名为项目1,点击create from archetype,我先选择org ...