100 atcoder#ABC157D. [ABC157D] Friend Suggestions
[ABC157D] Friend Suggestions
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.
4 4 1
2 1
1 3
3 2
3 4
4 1
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.
5 10 0
1 2
1 3
1 4
1 5
3 2
2 4
2 5
4 3
5 3
4 5
0 0 0 0 0
Everyone is a friend of everyone else and has no friend candidate.
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
1 3 5 4 3 3 3 3 1 0