WPC5G - The dilemma of Idli
It is emergency time! There has been a clash between the organizers of the Galactical Wars and the Inter-Galactic Parliament due to some feud. The entire civilization has been split into two groups A and B. The civilians in A love some particular members in the Organization Committee of the Galactical Wars, and hate some members from the Inter-Galactic Parliament. On the other hand, civilians in B love some particular members from the Inter-Galactic Parliament, and hate some in the Organization Committee.
You are Idli, the Inter-Galactic Dean, and it is your job to ensure satisfaction of the civilians. You decide to do so by impeaching some members from the Organization Committee and some from the Parliament. A civilian is satisfied if and only if all the members he loves are not impeached, and all the members he hates are impeached.
Of course, Idli wants to satisfy most number of civilians. Help Idli in devising an algorithm to do so.
Input
First line contains two space separated integers n1 and n2, denoting the number of Galactic Wars organizers (numbered 1 to n1) and the number of Members of Parliaments (MP) respectively (numbered 1 to n2).
Second line contains a single integer ’n’, denoting the number of civilians.
’n’ lines follow containing the description of the civilians in the following format:
First character contains a single character ‘A’, or ‘B’ denoting the group of the civilian.
Then there is a space.
Then some space separated integers follow ended by -1 denoting the members of same group whom he loves.
Then some space separated integers follow ended by -1 denoting the members of other group which he hates.
Output
A single integer denoting the maximum number of civilians Idli can satisfy.
Constraints
1 <= n1 <= 1000000
1 <= n2 <= 1000000
1 <= n <= 500
0 <= number of organizers/MPs a person loves <= 50
0 <= number of organizers/MPs a person hates <= 50
Example
Input 5 5 3 A 1 -1 5 3 -1 B 2 3 -1 2 5 -1 B -1 -1 Output 2
Explanation
The third person doesn’t love or hate anyone, and thus is always satisfied. Only 1 out of the first 2 civilians can be satisfied. Hence Idli can satisfy at max 2 civilians.
hide comments
Koderok:
2014-06-21 12:12:05
"A civilian is satisfied if and only if all the members he loves are not impeached...". Doesn't this mean that not all the members who are loved should be impeached ie. the civilian would be satisfied if there is at least one person remaining (not impeached) whom he loves? |
Added by: | triveni |
Date: | 2014-03-29 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | ACA judge IITK, WPC5 |