Kingdoms and Quarantine
Time limit8sMemory limit512 MB
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 (with cities) and (with cities), and bidirectional roads. Each road connects a city from and a city from . No pair of cities is connected by more than one road.
The cities in kingdom are numbered from to . The cities in kingdom are numbered from to . The roads are numbered from to . Road connects cities and , where and .
A dangerous virus appeared in one kingdom, so the Kings decided to close some roads.
Let be the initial number of roads connecting city to other cities, and let be the number of roads connecting city to other cities that are still active (not closed).
Road can be closed if and only if the following conditions hold before it is closed:
- It was not closed before.
- and have the same parity (both even or both odd).
- and 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 , , and : the number of cities in kingdom , the number of cities in kingdom , and the number of roads (, ).
The next lines describe the roads. Line contains two integers and , the cities connected by road (, ). For , either or .
Output
On the first line, print , the maximum number of roads that can be closed. On the second line, print integers (), 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, , , , , . Initially equals , so roads 1, 4, and 5 can be closed.
After closing road 1, and . Roads 4 and 5 can still be closed. After closing road 4, and , so only road 2 can be closed next. After closing road 2, , , , , and . No more than three roads can be closed.