#DSU0000054. Gợi ý kết bạn (Friend Suggestions)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Gợi ý kết bạn (Friend Suggestions)
Friend Suggestions
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
A social network contains users numbered from to . There are friendship pairs and blocking pairs. Both relations are undirected. Pairs do not repeat, and a pair cannot be both friends and blocked.
Two users belong to the same friendship network if a chain of friendships connects them, even if they have not directly befriended each other. For user , user is a potential friend suggestion if , they belong to the same friendship network, are not already direct friends, and have not blocked each other.
Determine the number of potential friend suggestions for every user. Counting suggestions does not change any friendship or blocking relation.
Input
Read ; then friendship pairs and block pairs. All pairs join distinct users, are unique within their categories, and no pair belongs to both categories.
Output
Print the candidate counts for the users.
Subtasks
- Subtask 1 (20 points): , ; ; there are no self-pairs, repeated pairs, or pairs belonging to both relation types.
- Subtask 2 (30 points): , ; ; there are no self-pairs, repeated pairs, or pairs belonging to both relation types.
- Subtask 3 (50 points): , ; ; there are no self-pairs, repeated pairs, or pairs belonging to both relation types.
Examples
Input
4 4 1
2 1
1 3
3 2
3 4
4 1
Output
0 1 0 1
Explanation
All four people belong to one friendship component. User is already friends with and has blocked , leaving no candidate. User can befriend . User is already friends with everyone else. User can befriend but has blocked . The result is 0 1 0 1.