codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1167C.md (1627B)


      1 Source: https://codeforces.com/problemset/problem/1167/C
      2 
      3 C. News Distribution
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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.
     22 
     23 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.
     24 
     25 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.
     26 
     27 Input
     28 
     29 The first line contains two integers $n$ and $m$ ($1 \le n, m \le 5 \cdot 10^5$) — the number of users and the number of groups of friends, respectively.
     30 
     31 Then $m$ lines follow, each describing a group of friends. The $i$-th line begins with integer $k_i$ ($0 \le k_i \le n$) — the number of users in the $i$-th group. Then $k_i$ distinct integers follow, denoting the users belonging to the $i$-th group.
     32 
     33 It is guaranteed that $\sum \limits_{i = 1}^{m} k_i \le 5 \cdot 10^5$.
     34 
     35 Output
     36 
     37 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.
     38 
     39 Example
     40 
     41 Input
     42 
     43 ```
     44 7 5
     45 3 2 5 4
     46 0
     47 2 1 2
     48 1 1
     49 2 6 7
     50 ```
     51 
     52 Output
     53 
     54 ```
     55 4 4 1 4 4 2 2
     56 ```