题目描述
Background
Once upon a time, there was a glorious kingdom, and Little A was the king. He believed that life needed to have meaning, so today he wanted to bestow significance upon his subjects.
Problem Description
Little A noticed that everyone's existence has an irreplaceable significance to others. The significance value of a person is defined as the number of their friends and friends of friends.
In Little A's kingdom, there are $n$ residents numbered $1, 2, \cdots, n$. Each resident has $x_i$ friends. Now, Little A wants to know the significance value of each resident.
Note that the friendship relationship may be one-way. That is, $a$ may consider $b$ a friend, but $b$ may not necessarily consider $a$ a friend. Also, if a person's friends of friends include themselves, this part is not counted.
As time goes by, friendships may fade. The way we maintain a connection with someone is simply by remembering them.
Input Format
The first line contains an integer $n$, representing the number of residents in Little A's kingdom.
The next $n$ lines each contain $x_i + 1$ integers. The first integer $x_i$ represents how many friends the $i$-th resident has, followed by $x_i$ integers representing the IDs of his friends.
Output Format
One line containing $n$ integers, each representing the significance value of each resident.
Sample Input and Output
Sample Input #1
4
2 2 3
1 4
0
0
Sample Output #1
3 1 0 0
Sample Input #2
3
0
2 1 3
0
Sample Output #2
0 2 0
Sample Input #3
3
1 2
1 3
1 1
Sample Output #3
2 2 2
Notes
Explanation of Sample 1
- Resident 1 considers his friends to be 2 and 3. Resident 3 has no friends, but resident 2 considers his friend to be 4. Therefore, resident 1's significance value is 3.
- Resident 2 considers his friend to be 4, and resident 4 has no friends. Therefore, resident 2's significance value is 1.
- Residents 3 and 4 both consider themselves to have no friends, so their significance values are 0.
Explanation of Sample 2
- Residents 1 and 3 consider themselves to have no friends, so their significance values are 0.
- Resident 2's friends are 1 and 3, and both 1 and 3 consider themselves to have no friends. Therefore, resident 2's significance value is 2.
Explanation of Sample 3
- Resident 1 considers his friend to be 2, and resident 2 considers his friend to be 3. Therefore, resident 1's significance value is 2.
- Resident 2's friend is 3, and resident 3 considers his friend to be 1. Therefore, resident 2's significance value is 2.
- Resident 3's friend is 1, and resident 1 considers his friend to be 2. Therefore, resident 3's significance value is 2.
Data Range
- For 20% of the data, $x_i \le 1$.
- For another 20% of the data, except for $x_1 = n - 1$, $x_i = 0$.
- For 100% of the data, $1 \le n \le 100$, $0 \le x_i \le n$. It is guaranteed that each integer $c$ (other than the first number in each line) satisfies $1 \leq c \leq n$ and is unique.
- The data ensures that there will be no cases where "a person is their own friend" or "a person is both a friend and a friend of a friend of another person."
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分