链接:

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的更多相关文章

  1. Codeforces 1167C - News Distribution

    题目链接:http://codeforces.com/problemset/problem/1167/C 题意:大概就是分成几个小团体,给每个人用1 - n编号,当对某个人传播消息的时候,整个小团体就 ...

  2. 【CodeForces - 1167C 】News Distribution(并查集)

    News Distribution 题意 大概就是分成几个小团体,给每个人用1 - n编号,当对某个人传播消息的时候,整个小团体就知道这个消息,输出 分别对1 - n编号的某个人传递消息时,有多少人知 ...

  3. 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 ...

  4. CCPC-Wannafly Summer Camp 2019 Day1

    A - Jzzhu and Cities CodeForces - 449B 题意:n座城市,m条路,k条铁路啥的吧,然后要求最多能删多少条铁路保持1到$n$的最短路不变. 思路:因为铁路是从1出发的 ...

  5. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  6. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  7. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  8. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  9. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  10. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

随机推荐

  1. mysql 8.0.12 安装配置方法图文教程

    一.安装 1.从网上下载MySQL8.0.12版本,下载地址 2. 下载完成后解压 我解压的路径是:D:\Java\mysql-8.0.12-winx64 3. 配置文件 首先在解压的路径下查看是否含 ...

  2. Stream流实现斐波那契数列

    1.前言 我们都知道斐波那契数列有很多种实现方法,在jdk1.8以前没有流操作,只能通过递归或者迭代等其他方式来实现斐波那契数列, 但是jdk1.8以后,有了流操作,我们就可以使用流来实现斐波那契数列 ...

  3. unity拖尾粒子问题

    拖尾粒子有一个问题就是当设置父物体时候,拖动父物体,就没有拖尾效果了 此时只需设置Emitter Velocity的类型为 transform 就行了 还有一种设置simulation space类型 ...

  4. IF-ELSE嵌套练习

    一,1,编写程序,由键盘输入三个整数分别存入变量num1,num2,num3中,对它们进行排序,使用if-else结构,并按从小到大的顺序输出: package practice; import ja ...

  5. mac os cmake安装

    1.下载安装程序,地址为 http://www.cmake.org/download/,下载 Unix/Linux Source (has \n line feeds) cmake-3.0.2.tar ...

  6. 暴力破解-DVWA_1.9-笔记

     穷举法  通过社工尽可能的缩小密码字典的范围   所用到的工具: Firefox浏览器及其插件Proxy Switcher, OWASP ZAP代理抓包工具. OWASP ZAP  代理抓包工具 h ...

  7. 为应用创建多个独立python运行环境

    在开发Python应用程序的时候,系统安装的Python3只有一个版本:3.4.所有第三方的包都会被pip安装到Python3的site-packages目录下. 如果我们要同时开发多个应用程序,那这 ...

  8. MySQL -2- 体系结构

    1. 体系结构 1.1 C/S(客户端/服务端)模型介绍   image TCP/IP方式(远程.本地): mysql -uroot -poldboy123 -h 10.0.0.51 -P3306 S ...

  9. 03: redis高级

    1.1 布隆过滤器 1.布隆过滤器是什么?(判断某个key一定不存在) 1. 本质上布隆过滤器是一种数据结构,比较巧妙的概率型数据结构 2. 特点是高效地插入和查询,可以用来告诉你 “某样东西一定不存 ...

  10. .net core 调用webservice

    原文:.net core 调用webservice 1.点击core项目添加链接的服务 2.键入对应的webservice地址,下载对应的代理服务 4.由于.net core  代理类只支持异步方法  ...