CitadelOA #18
Social Media Suggestions
Estimated MediumJudge-ready
Topics (AI-labelled)Hashing
For each person, recommend a user who is neither that person nor a direct friend, preferring the most mutual friends and then the smallest ID. A user with 0 mutual friends is still a candidate; return −1 only when there are no non-friends at all. The formal conditions of the original do not require a positive mutual count.
Input
The first line contains n m, followed by m lines of undirected edges. Original range of the complete same problem: 1≤n≤100000, 0≤m≤250000, IDs 0..n−1; there are no self-loops or multi-edges, each person has at most 15 friends, and the graph may be disconnected. The 1-based typo in the body of problem 18 is restored to 0-based according to the original constraints and examples.
Output
Output n recommended IDs, in order of users 0..n−1.
Example 1
Input:
5 5
0 1
0 2
1 3
2 3
3 4
Output:
3 2 1 0 1
Example 2
Input:
3 3
0 1
1 2
2 0
Output:
-1 -1 -1
Example 3
Input:
3 1
0 1
Output:
2 2 0
Example notes
The outputs of the three public examples are, in order: 3 2 1 0 1; -1 -1 -1; 2 2 0. These answers were verified by independent enumeration or direct simulation.
Editorial
Loading solution…