Under construction

Still being built. Things may change

Problem Setting

Time limit2sMemory limit512 MB

Summary
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 PP 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 PP, TT, and MM (1≤P1 \leq P, T≤105T \leq 10^5; 0≤M≤min⁡(106,P⋅T0 \leq M \leq \min(10^6, P \cdot T)): the number of participants, the number of problems, and the number of participant-problem pairs where the participant knows the problem.

The next MM lines describe the problems known to participants. Each line contains two integers uu and vv (1≤u≤P;1≤v≤T1 \leq u \leq P; 1 \leq v \leq T): 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 P0P_0 and T0T_0: 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 T0T_0 numbers: the numbers of the problems in the chosen set. All numbers must be distinct positive integers not exceeding TT. 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.

Examples2

  1. Example 1

    Input
    3 4 6
    1 1
    1 2
    2 2
    2 3
    3 3
    3 4
    
    Expected output
    2 1
    1
    
  2. Example 2

    Input
    3 5 6
    1 1
    1 2
    2 1
    2 3
    3 1
    3 3
    
    Expected output
    3 2
    4 5