Goose, Goose, Ducks?
Memory limit1024 MB
Find the fewest attendees who can be ducks so that goose statements fit all duck meetings and no duck statement contradicts earlier goose statements.
- Level
Hard9 of 10
- Topics
- Graph, Union-find, Implementation
- Solved
- No attempts yet
Problem
The first international Geese conference just wrapped up. It should have been a happy occasion, but it ended on a bittersweet note. The organizers found a paper with detailed plans for a duck infiltration, and they are now trying to identify the infiltrating group among the attendees.
The document contained a list of triples of integers . Each triple means the ducks would meet exactly seconds after the start of the conference at point , which is meters east and meters north of the center of the conference floor. A goose may or may not have been at that point at that time. Every duck certainly was.
Ducks and geese both walk at a maximum speed of 1 meter per second. An attendee at point at time can reach by time as long as . Each attendee's position at time 0 can be any point, independently of the other attendees.

After the discovery, the group held a questioning session to identify the ducks. Attendees made statements one at a time. The -th statement was made by attendee , who claimed that both and attendee were at point exactly seconds after the start of the conference. A point in a statement may or may not be a point where a duck meeting happened.
Statements from geese are always true, but ducks may lie. Ducks know which attendees are ducks and which are geese. To avoid getting caught, ducks only make statements that are consistent with all earlier statements made by geese. Statements from geese are consistent with all ducks being at all duck meetings.
A hypothesis is a partition of all attendees into a set of ducks (-ducks) and a set of geese (-geese). is consistent with a set of statements if every attendee has a path moving at most 1 meter per second such that:
- all -ducks are at all duck meetings, and
- for each statement in claiming that saw at point at time , the paths of both and pass through at time .
A hypothesis is feasible under a set of statements if:
- -ducks is not empty, so at least one duck exists,
- the statements in made by -geese are consistent with , so geese tell the truth, and
- for each statement made by an -duck, let be the set of statements made by -geese before . Then there is some hypothesis , which may or may not equal , such that is consistent with . So ducks do not contradict earlier goose statements.
The hypothesis in which every attendee is a duck is always feasible.
Find the minimum size of -ducks over all feasible hypotheses .
Input
The first line contains the number of test cases . Each test case starts with a line containing three integers , , and , the numbers of attendees, duck meetings, and statements.
The next lines each contain three integers , , and . This means there was a duck meeting at point , exactly seconds after the start of the conference.
The last lines of the test case each describe a statement with five integers , , , , and . Attendee stated that and were both at point exactly seconds after the start of the conference. Statements are given in the order they were issued.
Output
For each test case, output one line containing Case #x: y, where is the test case number starting from 1 and is the minimum number of ducks that might have infiltrated the conference.
Constraints
- .
- for all .
- for all .
- for all .
- for all .
- for all .
- for all .
- for all .
- for all .
- for all .
- for all .
- for all .
- for all .
Hint
In Sample Case #1, attendee 1 being the only duck is a feasible hypothesis.
In Sample Case #2, attendees 2 and 4 being the only ducks is a feasible hypothesis. There is at least one duck, so all attendees being geese is not feasible.