

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
とあるSNSに、人 、人 、 、人 が登録しています。
この 人の間には、 組の「友達関係」と、 組の「ブロック関係」が存在します。
について、人 と人 は友達関係にあります。この関係は双方向的です。
について、人 と人 はブロック関係にあります。この関係は双方向的です。
以下の つの条件が満たされるとき、人 は人 の「友達候補」であると定義します。
- である。
- 人 と人 はブロック関係に無い。
- 人 と人 は友達関係に無い。
- 以上 以下の整数から成るある数列 が存在し、 であり、 であり、 について、人 と人 は友達関係にある。
人 について、友達候補の数を答えてください。
制約
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
出力
答えを空白区切りで順に出力せよ。
入力例 1Copy
4 4 1 2 1 1 3 3 2 3 4 4 1
出力例 1Copy
0 1 0 1
人 と人 は友達関係にあり, 人 と人 は友達関係にあり, かつ人 と人 は友達関係にもブロック関係にもありませんから, 人 は人 の友達候補です。
人 と人 は人 の友達候補ではありませんから, 人 の友達候補は 人です。
入力例 2Copy
5 10 0 1 2 1 3 1 4 1 5 3 2 2 4 2 5 4 3 5 3 4 5
出力例 2Copy
0 0 0 0 0
全ての人は他の全ての人と友達関係にありますが、友達候補は 人です。
入力例 3Copy
10 9 3 10 1 6 7 8 2 2 5 8 4 7 3 10 9 6 4 5 8 2 6 7 5 3 1
出力例 3Copy
1 3 5 4 3 3 3 3 1 0
Score : points
Problem Statement
An SNS has users - User , User , , User .
Between these users, there are some relationships - friendships and blockships.
For each , there is a bidirectional friendship between User and User .
For each , there is a bidirectional blockship between User and User .
We define User to be a friend candidate for User when all of the following four conditions are satisfied:
- .
- There is not a friendship between User and User .
- There is not a blockship between User and User .
- There exists a sequence consisting of integers between and (inclusive) such that , , and there is a friendship between User and for each .
For each user , how many friend candidates does it have?
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answers in order, with space in between.
Sample Input 1Copy
4 4 1 2 1 1 3 3 2 3 4 4 1
Sample Output 1Copy
0 1 0 1
There is a friendship between User and , and between and . Also, there is no friendship or blockship between User and . Thus, User is a friend candidate for User .
However, neither User or is a friend candidate for User , so User has one friend candidate.
Sample Input 2Copy
5 10 0 1 2 1 3 1 4 1 5 3 2 2 4 2 5 4 3 5 3 4 5
Sample Output 2Copy
0 0 0 0 0
Everyone is a friend of everyone else and has no friend candidate.
Sample Input 3Copy
10 9 3 10 1 6 7 8 2 2 5 8 4 7 3 10 9 6 4 5 8 2 6 7 5 3 1
Sample Output 3Copy
1 3 5 4 3 3 3 3 1 0