CodeForces-1167C
链接:
https://vjudge.net/problem/CodeForces-1167C
题意:
In some social network, there are n users communicating with each other in m groups of friends. Let's analyze the process of distributing some news between users.
Initially, some user x 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 x you have to determine what is the number of users that will know the news if initially only user x starts distributing it.
思路:
并查集, 在统计一个组的人数.
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
//#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
#include <string>
#include <assert.h>
#define MINF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int MAXN = 5e5+10;
int Fa[MAXN], Sum[MAXN];
int n, m;
int GetF(int x)
{
if (Fa[x] == x)
return x;
Fa[x] = GetF(Fa[x]);
return Fa[x];
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 1;i <= n;i++)
Fa[i] = i;
for (int i = 1;i <= m;i++)
{
int k, h, v;
cin >> k;
if (k)
cin >> h;
int he = GetF(h);
for (int j = 1;j < k;j++)
{
cin >> v;
int tv = GetF(v);
if (tv != he)
Fa[tv] = he;
}
}
for (int i = 1;i <= n;i++)
{
int t = GetF(i);
Sum[t]++;
}
for (int i = 1;i <= n;i++)
cout << Sum[GetF(i)] << ' ';
cout << endl;
return 0;
}
CodeForces-1167C的更多相关文章
- Codeforces 1167C - News Distribution
题目链接:http://codeforces.com/problemset/problem/1167/C 题意:大概就是分成几个小团体,给每个人用1 - n编号,当对某个人传播消息的时候,整个小团体就 ...
- 【CodeForces - 1167C 】News Distribution(并查集)
News Distribution 题意 大概就是分成几个小团体,给每个人用1 - n编号,当对某个人传播消息的时候,整个小团体就知道这个消息,输出 分别对1 - n编号的某个人传递消息时,有多少人知 ...
- Codeforces 1167c(ccpc wannafly camp day1) News Distribution 并查集模板
题目: In some social network, there are nn users communicating with each other in mm groups of friends ...
- CCPC-Wannafly Summer Camp 2019 Day1
A - Jzzhu and Cities CodeForces - 449B 题意:n座城市,m条路,k条铁路啥的吧,然后要求最多能删多少条铁路保持1到$n$的最短路不变. 思路:因为铁路是从1出发的 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- slideToggle()---单击隐藏/浮现--jQuery--click() 方法
click() 方法 模块隐藏/浮现 <html> <head> <script type="text/javascript" src="/ ...
- 二叉搜索树倒序O(nlogn)建树
由于在某些糟糕情况下,二叉查找树会退化成链,故而朴素建树过程其复杂度可能会退化成\(O(n^2)\). 采用倒序连边建树的方法可以使得二叉查找树建树复杂度稳定在\(O(nlogn)\). 具体思路如下 ...
- 最新的省市编码和sql
下面的项目是整理的最新的省市编码sql文件,可以看看. github
- [转帖]C#中字典集合HashTable、Dictionary、ConcurrentDictionary三者区别
C#中字典集合HashTable.Dictionary.ConcurrentDictionary三者区别 https://blog.csdn.net/yinghuolsx/article/detail ...
- 解决PHP上传文件、下载文件中由于文件过大导致的上传失败及下载不全问题
用php+apache上传文件的时候,由于文件过大,容易导致上传失败, 解决办法:修改php.ini中:upload_max_filesize 2m 即允许上传文件大小的最大值.默认为2M ,大小 ...
- 多线程之小米商店APP爬虫
#今日目标 **多线程之小米商店APP爬虫** 爬取小米商店所有社交APP ``` import requests import time from threading import Thread f ...
- E - 卿学姐与城堡的墙(树状数组求逆序数)
卿学姐与城堡的墙 Time Limit: 2000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit ...
- 弹出ifream
top.$.jBox("iframe:"+'${ctx}/synopsis/hmlwxSynopsis/addItem', {title: "添加作品",w ...
- 12.AutoMapper 之Null替换(NullSubstitution)
https://www.jianshu.com/p/3f86f237d1db Null 替换(Null Substitution) Null 替换允许当源类型成员在成员链任何位置为Null时给目标成员 ...
- mysql远程连接错误10038--navicat for mysql (10038)
1.确定3306端口是否对外开放 如果是阿里云服务器,需要添加安全组规则 2.授权 执行sql,账号密码按照自己服务器而定 grant all privileges on *.* to 'root'@ ...