#B4013. The Significance Value Problem
The Significance Value Problem
The Significance Value Problem
Careful resident A discovered that every individual's existence holds an irreplaceable meaning to others. The significance value of a person is defined as the number of his friends and friends of friends (i.e. nodes that are reachable in at most 2 directed steps), excluding himself if he appears among his friends of friends.
The kingdom has $n$ residents numbered $1, 2, \ldots, n$. Each resident $i$ has $x_i$ friends. Note that the friendship relation is directional which means if resident $a$ considers resident $b$ a friend, resident $b$ may not necessarily consider resident $a$ a friend.
You are given the information about each resident's friends. Your task is to calculate the significance value for every resident.
Input Format: The first line contains an integer $n$, the number of residents. Each of the following $n$ lines starts with an integer $x_i$ (the number of friends of resident $i$) followed by $x_i$ integers representing the friend IDs of resident $i$. Each friend ID is between $1$ and $n$.
Note: If a resident appears as a friend of a friend (i.e. in the second level) but is already a direct friend, count him only once. Also, if a resident appears in his own friend-of-friend list, do not count him.
inputFormat
The first line contains a single integer $n$ — the number of residents. Each of the next $n$ lines describes a resident. The $i$-th line begins with an integer $x_i$, the number of friends of resident $i$, followed by $x_i$ space-separated integers representing the friend IDs of resident $i$.
outputFormat
Output $n$ integers separated by a space. The $i$-th integer should be the significance value of resident $i$, which is the count of distinct residents that are either a direct friend of $i$ or a friend of one of $i$'s friends, excluding resident $i$ itself.
sample
3
2 2 3
0
0
2 0 0