Sophie's Birthday Party
Time limit3sMemory limit128 MB
Given objections between kids, find the largest set with no objection inside it, i.e. the maximum independent set, or NIE if it is below k.
- Level
Hard8 of 10
- Topics
- Graph, Greedy, Brute force, Math
- Solved
- No attempts yet
Problem
Little Sophie is throwing a birthday party and has written a tentative list of kindergarten friends she would like to invite. The kids, however, are demanding guests: some of them refuse to come if certain other kids are also invited. For example, Mary agrees to come only if neither Camille nor Emily is present, because they took her doll last week; little Christopher will only play with Sophie and Camille and does not want to see anyone else; and so on.
We describe these wishes as objections: an objection means that kid does not want to meet kid at the party. Sophie considers the party a success if no invited guest has an objection against any other invited guest. In other words, if kid objects to kid or kid objects to kid , then and cannot both be invited.
Sophie will leave out some kids to make sure the party succeeds, but she wants to invite as many kids as possible. If she cannot invite at least kids, she will not hold the party at all.
Given all the objections, determine the largest number of kids Sophie can invite so that the party is a success, or decide that inviting at least kids is impossible.
Input
The first line contains two integers and separated by a single space: is the number of Sophie's acquaintances and is the minimum number of kids she wants to invite, with and . The kids are numbered from to .
The second line contains a single integer , the number of objections, with .
Each of the following lines contains two integers and separated by a single space (, ), meaning that kid does not want to meet kid at the party. Each ordered pair appears at most once.
Output
If it is impossible to invite at least kids so that the party is a success, print a single line containing the word NIE.
Otherwise, print a single integer: the maximum number of kids that can be invited so that the party is a success.
Hint
