Party
Time limit3sMemory limit128 MB
Run a deterministic greedy procedure where each vertex is added to a clique candidate if it knows everyone on the list, otherwise the smallest non-neighbor is removed, then print the smallest n/3 remaining.
- Level
Medium7 of 10
- Topics
- Greedy, Graph, Implementation, Math
- Solved
- No attempts yet
Problem
Byteasar intends to throw a party. Naturally, he would like it to be a success. He is quite certain that it will be a success as long as every invited guest knows one another. Right now he is trying to put together a list of the friends he would like to invite.
Byteasar has friends, and is divisible by . Luckily, most of his friends know one another. He also recalls that he once attended a party with of his friends where everyone knew everyone else. Unfortunately, he does not remember much else about that party; in particular, he has no idea which of his friends were there.
Byteasar does not feel obliged to throw a huge party, but he would like to invite at least of his friends. He has no idea how to pick them, so he asks you for help: find friends who all know one another.
Input
The first line of the standard input contains two integers and , separated by a single space (, , and is divisible by ). They denote the number of Byteasar's friends and the number of pairs of his friends who know each other, respectively. The friends are numbered from to .
Each of the following lines contains two integers separated by a single space. The numbers and () on line (for ) mean that persons and know each other. Every pair appears at most once in the input.
Output
Many different groups may satisfy the requirement, so build the guest list with the following deterministic procedure to make the answer unique.
Start with an empty guest list. Consider the friends one by one, from friend to friend . When you consider friend :
- if friend already knows everyone currently on the guest list, add to the list;
- otherwise, remove from the list the lowest-numbered person who does not know , and do not add .
After all friends have been considered, everyone remaining on the guest list knows everyone else, and at least people remain. Print, on a single line in increasing order and separated by single spaces, the lowest-numbered people on the final guest list.
Hint

In the example graph, friends all know one another. Applying the procedure above from friend onward leaves on the final guest list, so the output is 3 4.