PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#DSU0000024. Phân phối tin tức (News Distribution)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Phân phối tin tức (News Distribution)

News Distribution

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A social network contains nn people, numbered from 11 to nn, and mm chat groups. A person may belong to several groups or to none. When someone in a group knows a piece of news, they may share it with every other member of that group.

Anyone who receives the news can, in turn, share it in all groups they belong to. This continues until no additional person can learn the news. A group may be empty or contain just one member; such a group cannot transmit the news between different people.

For each person ii, consider an independent scenario in which initially only ii knows the news. Determine how many people eventually know it, including ii.

Input

The first line contains n,mn,m. Each of the next mm lines starts with kik_i, followed by kik_i distinct user indices belonging to the group.

Output

Print nn integers; the ii-th is the number of users who eventually know the news when user ii starts.

Subtasks

  • Subtask 1 (20 points): 1≤n,m≤201\le n,m\le20, ∑ki≤100\sum k_i\le100; 0≤ki≤n0\le k_i\le n; each user ID lies in [1,n][1,n] and is listed at most once per group.
  • Subtask 2 (30 points): 1≤n,m≤42001\le n,m\le4200, ∑ki≤20000\sum k_i\le20000; 0≤ki≤n0\le k_i\le n; each user ID lies in [1,n][1,n] and is listed at most once per group.
  • Subtask 3 (50 points): 1≤n,m≤5⋅1051\le n,m\le5\cdot10^5, ∑ki≤5⋅105\sum k_i\le5\cdot10^5; 0≤ki≤n0\le k_i\le n; each user ID lies in [1,n][1,n] and is listed at most once per group.

Examples

Input

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

Output

4 4 1 4 4 2 2

Explanation

The groups {2,5,4} and {1,2} connect users {1,2,4,5}, so each of them reaches 4 users. User 3 is isolated; users {6,7} reach 2 users.