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 ...
随机推荐
- BZOJ 1680 [Usaco2005 Mar]Yogurt factory:贪心【只用考虑上一个】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1680 题意: 在接下来的n周内,第i周生产一吨酸奶的成本为c[i],订单为y[i]吨酸奶. ...
- Elasticsearch mapping文档相似性算法
Elasticsearch allows you to configure a scoring algorithm or similarity per field. The similarityset ...
- hdu-5656 CA Loves GCD(dp+数论)
题目链接: CA Loves GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- BZOJ - 4518: 征途(斜率优化,求N数划分为M区间的最小方差)
注意初始化...等等补 #include<bits/stdc++.h> #define ll long long using namespace std; ; int q[maxn],he ...
- HihoCoder1655 : 第K小最简真分数([Offer收割]编程练习赛39)(唯一分解+容斥定理+二分)(不错的数学题)
描述 给一个整数N,请你求出以N为分母的最简(既约)真分数中第K小的是多少? 输入 两个整数N个K. 对于30%的数据,1 <= N <= 1000000 对于100%的数据,1 < ...
- Redo Gap 处理与优化
理论背景 当redo data 传送发生中断时就会产生redo gap.当redo 传送恢复正常以后,redo transport service 会自动检测redo gap并发送缺失的redo 到d ...
- BZOJ3165:[HEOI2013]Segment
浅谈标记永久化:https://www.cnblogs.com/AKMer/p/10137227.html 题目传送门:https://www.lydsy.com/JudgeOnline/proble ...
- Mysql MMM 高可用
一.Mysql MMM 高可用概况: mmm_mond 负责所有的监控工作的监控守护进程,决定节点的移除等: mmm_agentd 运行在mysql服务器上的代理守护进程,通过简单远程服务集提供给 ...
- bootstrap模版兼容IE浏览器代码嵌入
1. bootstrap模板为使IE6.7.8版本(IE9以下版本)浏览器兼容html5新增的标签,引入下面代码文件即可. <script src="https://oss.maxc ...
- Jmeter查看结果树Unicode编码转中文方法
本文为转载微信公众号文章,如作者发现后不愿意,请联系我进行删除 在jmeter工具的使用中,不管是测试接口还是调试性能时,查看结果树必不可少,然而在查看响应数据时,其中的中文经常以Unicode的编码 ...