#DSU0000024. Phân phối tin tức (News Distribution)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Phân phối tin tức (News Distribution)
News Distribution
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A social network contains people, numbered from to , and 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 , consider an independent scenario in which initially only knows the news. Determine how many people eventually know it, including .
Input
The first line contains . Each of the next lines starts with , followed by distinct user indices belonging to the group.
Output
Print integers; the -th is the number of users who eventually know the news when user starts.
Subtasks
- Subtask 1 (20 points): , ; ; each user ID lies in and is listed at most once per group.
- Subtask 2 (30 points): , ; ; each user ID lies in and is listed at most once per group.
- Subtask 3 (50 points): , ; ; each user ID lies in 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.