Problem Setting
Time limit2sMemory limit512 MB
Given participant-to-problem edges, pick a nonempty problem set maximizing first the eliminated participants (those knowing any chosen problem) then the set size.
- Level
Medium5 of 10
- Topics
- Greedy, Graph, Hash map, Implementation
- Solved
- No attempts yet
Problem
To prepare problems for the upcoming contest, the organizers invited experienced participants of this same contest. Each of them knows some set of problems. The participants like sharing problem ideas, so a problem may be known to several participants. Unfortunately, if a participant knows at least one problem from the set chosen for the contest, they cannot take part in it.
The organizers care about the size of the contest, so they want to choose the problems so that as many participants as possible can take part. The set of problems must be nonempty and, if possible, as large as possible.
The organizers are not programmers, so they have trouble assembling the problems the required way. They ask you to help them.
Input
The first line contains three integers , , and (, ; )): the number of participants, the number of problems, and the number of participant-problem pairs where the participant knows the problem.
The next lines describe the problems known to participants. Each line contains two integers and (): the number of a participant and the number of one problem they know. For each participant, every problem they know is listed exactly once.
Output
In the first line output two numbers and : the number of participants and problems found. Note that the number of participants must be maximized first, and given the maximum number of participants, the number of problems must be maximized.
In the second line output numbers: the numbers of the problems in the chosen set. All numbers must be distinct positive integers not exceeding . If several optimal solutions exist, output any of them.
Hint
In the first example, problem 4 could also be taken, since exactly one person knows it.
In the second example, nobody knows problems 4 and 5, so taking those is best.