PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000045. Bạn của bạn (Friends of Friends)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Bạn của bạn (Friends of Friends)
Friends of Friends
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
For each person in an undirected friendship network, count other people who are not directly friends but share at least one mutual friend.
Input
Integers followed by undirected friendship edges .
Output
Print lines, one friends-of-friends count per person.
Subtasks
- Subtask 1 (40 points): ; , ; distinct undirected edges, no loops, 1-indexed vertices.
- Subtask 2 (60 points): , ; distinct undirected edges, no loops, 1-indexed vertices.
Examples
Input
3 2
1 2
2 3
Output
1
0
1
Explanation
People 1 and 3 have a common friend 2 and are not direct friends, giving each one friend-of-friend. Person 2 already knows both directly.