This page is still under construction.

Parts of this page are still being built. What you see may change.

Kingdoms and Quarantine

Time limit8sMemory limit512 MB

Summary
Given a bipartite graph of roads between two kingdoms, find the most roads that can be closed under parity rules and print one valid closing order.
Level

Hard9 of 10

Topics
Math, Graph, Implementation
Solved
No attempts yet

Problem

There are two kingdoms AA (with N1N_1 cities) and BB (with N2N_2 cities), and MM bidirectional roads. Each road connects a city from AA and a city from BB. No pair of cities is connected by more than one road.

The cities in kingdom AA are numbered from 11 to N1N_1. The cities in kingdom BB are numbered from N1+1N_1 + 1 to N1+N2N_1 + N_2. The roads are numbered from 11 to MM. Road ii connects cities aia_i and bib_i, where 1≤ai≤N11 \le a_i \le N_1 and N1+1≤bi≤N1+N2N_1 + 1 \le b_i \le N_1 + N_2.

A dangerous virus appeared in one kingdom, so the Kings decided to close some roads.

Let DjD_j be the initial number of roads connecting city jj to other cities, and let djd_j be the number of roads connecting city jj to other cities that are still active (not closed).

Road xx can be closed if and only if the following conditions hold before it is closed:

  • It was not closed before.
  • daxd_{a_x} and DbxD_{b_x} have the same parity (both even or both odd).
  • dbxd_{b_x} and DaxD_{a_x} have the same parity (both even or both odd).

Find the maximum number of roads that can be closed, and a sequence of closing operations that achieves this maximum.

Input

The first line contains three integers N1N_1, N2N_2, and MM: the number of cities in kingdom AA, the number of cities in kingdom BB, and the number of roads (1≤N1,N2,M≤30001 \le N_1, N_2, M \le 3000, 1≤M≤N1⋅N21 \le M \le N_1 \cdot N_2).

The next MM lines describe the roads. Line ii contains two integers aia_i and bib_i, the cities connected by road ii (1≤ai≤N11 \le a_i \le N_1, N1+1≤bi≤N1+N2N_1 + 1 \le b_i \le N_1 + N_2). For i≠ji \ne j, either ai≠aja_i \ne a_j or bi≠bjb_i \ne b_j.

Output

On the first line, print KK, the maximum number of roads that can be closed. On the second line, print KK integers rir_i (1≤ri≤M1 \le r_i \le M), the numbers of the roads to close, in the order they are closed.

If several optimal answers exist, print any of them.

Hint

In the first sample, D1=3D_1 = 3, D2=2D_2 = 2, D3=1D_3 = 1, D4=2D_4 = 2, D5=2D_5 = 2. Initially dd equals DD, so roads 1, 4, and 5 can be closed.

After closing road 1, d1=2d_1 = 2 and d3=0d_3 = 0. Roads 4 and 5 can still be closed. After closing road 4, d2=1d_2 = 1 and d4=1d_4 = 1, so only road 2 can be closed next. After closing road 2, d1=1d_1 = 1, d2=1d_2 = 1, d3=0d_3 = 0, d4=0d_4 = 0, and d5=2d_5 = 2. No more than three roads can be closed.

Examples3

  1. Example 1

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

    Input
    1 2 2
    1 2
    1 3
    
    Expected output
    0
    
  3. Example 3

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