WeRideOA #4
Friend Recommendation System (Max Common Friends)
Estimated MediumJudge-ready
Topics (AI-labelled)HashingUnion-Find
Users are numbered 0..n−1, and the input gives undirected friendships. For each user y, among users who are neither y nor a friend of y, choose the one with the most mutual friends; break ties by the smallest number. If there is no candidate, the result is -1.
The original problem's ordering rule and the limit of at most 15 friends per person are explicit; this site adds no duplicate edges and the input/output protocol.
Input
The first line contains n m (1≤n≤100000); each of the next m lines is a pair of distinct user numbers. Friendships have no duplicates, are undirected, and each person has at most 15 friends.
Output
Output n recommended numbers in order of user number.
Example 1
Input:
3 0
Output:
1 0 0
Example 2
Input:
4 2
0 1
1 2
Output:
2 3 0 0
Example 3
Input:
5 4
0 1
0 2
1 3
2 3
Output:
3 2 1 0 0
Editorial
Loading solution…