A Midsummer Night's Dream
Time limit2sMemory limit512 MB
Simulate sightings and potion timings to determine who each dosed person first sees, then count mutual pairs.
- Level
Medium7 of 10
- Topics
- Simulation, Implementation, Sorting, Geometry
- Solved
- No attempts yet
Problem
In the comedy A Midsummer Night's Dream, Helena loves Demetrius, Demetrius loves Hermia, and Hermia loves Lysander, who loves her back. Hermia's father wants to force her to marry Demetrius, so she and Lysander run away. Demetrius chases them, and Helena chases Demetrius. Once the fairies hear about this mess, they decide to spend part of their own love potion on the humans instead. The potion, applied to the eyelids of a sleeping person, makes that person fall in love with the first person they see after waking up. Puck, the sprite who applies the potion, cannot tell the humans apart yet and puts it on the wrong people.
Count how many real couples come out of Puck's mistakes. A couple is two people who love each other.
For every person you are given the places where the person was seen and when, plus the time the potion was applied. You are also given the distance that people can see. From the moment the potion is applied to person , falls in love with the first person whose distance to is at most . Someone already inside the range of at the exact moment Puck applies the potion counts as a candidate. If several people are inside the range of at that same first moment, falls in love with the closest one. The input never makes two candidates equally close. Distance is Euclidean, and a distance of exactly is inside the range. Nobody falls in love with themselves, and if nobody ever comes inside the range, loves nobody.
Input
The first line contains (), the number of data sets. data sets follow, each in this form.
The first line of a data set contains two integers and . is the number of people and is the distance people can see.
Then come the descriptions of the people, numbered through . For person , one line contains two integers and . is the time when the potion was applied to person , and means the potion was never applied to . is the number of locations at which was seen. The next line contains the three integers , , repeated times. are the coordinates of the th sighting of , and is the time of that sighting. For each person the triples are sorted by increasing .
Person stays at from time until the next sighting at time , or until time is over if there is no next sighting. Before the first sighting, person is somewhere far away: nobody sees and sees nobody. A person with stays far away the whole time.
No two potion applications happen at the same time, and no potion application happens at the same time as a sighting. Two different people can be sighted at the same time.
Output
For each data set, output Data Set x: on a line by itself, where is the number of the data set, counting from . Then, on a line by itself, output the number of couples, that is the number of pairs of people who love each other. Follow each data set with a blank line.