CF1167C.News Distribution

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

在某个社交网络中,有 nn 个用户通过 mm 个朋友群组相互交流。我们来分析新闻在用户之间传播的过程。

初始时,某位用户 xx 从某个信源接收到新闻。随后,该用户将其转发给自己的所有好友(若存在至少一个群组同时包含两名用户,则称这两名用户互为好友)。好友们继续将新闻转发给各自的好友,依此类推。当不存在这样一对好友:其中一人已知新闻而另一人尚不知时,传播过程结束。

对每位用户 xx,你需要计算:若仅由用户 xx 初始发起新闻传播,最终共有多少名用户会得知该新闻。

输入格式

The first line contains two integers nn and mm (1≤n,m≤5⋅1051 \le n, m \le 5 \cdot 10^5) — the number of users and the number of groups of friends, respectively.

Then mm lines follow, each describing a group of friends. The ii-th line begins with integer kik_i (0≤ki≤n0 \le k_i \le n) — the number of users in the ii-th group. Then kik_i distinct integers follow, denoting the users belonging to the ii-th group.

It is guaranteed that ∑i=1mki≤5⋅105\sum \limits_{i = 1}^{m} k_i \le 5 \cdot 10^5.

第一行包含两个整数 nn 和 mm(1≤n,m≤5⋅1051 \le n, m \le 5 \cdot 10^5),分别表示用户数量和好友群组数量。

接下来是 mm 行,每行描述一个好友群组。第 ii 行以整数 kik_i(0≤ki≤n0 \le k_i \le n)开头,表示第 ii 个群组中的用户数量;随后是 kik_i 个互不相同的整数,表示属于第 ii 个群组的用户编号。

保证 ∑i=1mki≤5⋅105\sum \limits_{i = 1}^{m} k_i \le 5 \cdot 10^5。

输出格式

Print nn integers. The ii-th integer should be equal to the number of users that will know the news if user ii starts distributing it.

输出 nn 个整数。其中第 ii 个整数应等于:若由用户 ii 开始传播该消息,则最终知晓该消息的用户总数。

输入输出样例

  • 输入#1

    7 5
    3 2 5 4
    0
    2 1 2
    1 1
    2 6 7

    输出#1

    4 4 1 4 4 2 2

输入解题思路,AI测评打分。不知道怎么写?

首页