CF1167C.News Distribution
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
输入格式
The first line contains two integers n and m ( 1≤n,m≤5⋅105 ) — the number of users and the number of groups of friends, respectively.
Then m lines follow, each describing a group of friends. The i -th line begins with integer ki ( 0≤ki≤n ) — the number of users in the i -th group. Then ki distinct integers follow, denoting the users belonging to the i -th group.
It is guaranteed that i=1∑mki≤5⋅105 .
输出格式
Print n integers. The i -th integer should be equal to the number of users that will know the news if user i starts distributing it.
输入输出样例
输入#1
7 5 3 2 5 4 0 2 1 2 1 1 2 6 7
输出#1
4 4 1 4 4 2 2