博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Educational Codeforces Round 65 (Rated for Div. 2) C. News Distribution
阅读量:7088 次
发布时间:2019-06-28

本文共 1584 字,大约阅读时间需要 5 分钟。

链接:

题意:

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 
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;}

  

转载于:https://www.cnblogs.com/YDDDD/p/10900265.html

你可能感兴趣的文章
JS 调用WCF config
查看>>
分页思路
查看>>
图像处理工具包ImagXpress使用教程:多页TIFF编辑API的使用(二)
查看>>
4.Hbase Shell 命令
查看>>
caret彻底的理解css的三角形【通过border】
查看>>
ios 多选删除,
查看>>
YZMHelper(验证码类)
查看>>
解决 “VS2005 这个产品的配置数据已损坏。请与技术支持人员联系”不能部署的问题...
查看>>
AWS 学习之路(技术专业人员Training and Certification)核心服务部分
查看>>
第二次作业--邓琨
查看>>
Here's to the crazy ones(苹果的价值观)
查看>>
【HDOJ】1408 盐水的故事
查看>>
POJ2155 Matrix(二维树状数组)
查看>>
leetcode 172. Factorial Trailing Zeroes
查看>>
日常总结!!!
查看>>
Fidder的几点补充
查看>>
最佳sql server 分页查询
查看>>
如何改变EntityFramework的代码生成策略
查看>>
GO语言的进阶之路-面向对象编程
查看>>
Nginx的基本配置案例
查看>>