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 ...
随机推荐
- html5基本格式
html5基本格式 学习要点: HTML5 文档的基本格式 2. 开发工具的基本操作 一. 文档基本格式 <!DOCTYPE html> 文档声明,告诉计算机这是一个HTML5文档. ...
- “libgomp.so.1: version `GOMP_4.0' not found” || “libstdc++.so.6: version `CXXABI_1.3.8' not found”错误
类似问题还有 'ImportError ../lib/libstdc++.so.6: version `CXXABI_1.3.7' not found (required by xxx)'. ...
- mysql数据库---编码格式基本操作
1.查看数据库编码格式 mysql> show variables like 'character_set_database'; 2.查看数据表的编码格式 mysql> show crea ...
- 基于STM32的uCGUI移植和优化
基于STM32的uCGUI移植和优化 首先在开始这个说明之前,要简要说明下具体的环境: 编译工具:MDK4.20 开发板:安富莱v2版开发板 调试器:JLink v8盗版 移植篇 相信大家有移植经验 ...
- BZOJ4571:[SCOI2016]美味
浅谈主席树:https://www.cnblogs.com/AKMer/p/9956734.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem.p ...
- C++ ADO连接
#include "stdafx.h" #include <iostream> #include <iomanip> #include "wind ...
- 水题 等差数列HDU 5400 Arithmetic Sequence
主要是要知道它对于等差数列的定义,单个数也可以作为等差数列且一定满足题意,另外就是要算清楚区间与区间的关系,考虑两大类情况,一种是d1区间和d2区间连在一起,另外一种情况就是其余情况. #includ ...
- ubuntu 18.04 设置中文输入法
有下面几种常用选择: IBus拼音:sudo apt-get install ibus-pinyin IBUS五笔:sudo apt-get install ibus-table-wubi 谷歌拼音输 ...
- python 带参数运行
近段时间学考,又爱上了游戏.LOL nba2k 使命召唤 哎! 因为使命召唤的原因 有时候会卡住 然后点关闭没用. 然后任务管理器打不开 所以我想写个杀掉这个程序的东西. 当然写一下是简单.但 ...
- JavaScript高级程序设计学习笔记第八章--BOM
1.间歇调用和超时调用: 超时调用:需要使用 window 对象的 setTimeout()方法,它接受两个参数:要执行的代码和以毫秒表示的时间(即在执行代码前需要等待多少毫秒).其中,第一个参数可以 ...