Members move along timed polygonal routes around a fixed camera, and you may switch followers only when two members lie on the same ray; maximize total time filming a singing member.
Hard8GeometryDynamic programmingIntervalsNo attempts yetTime limit8sMemory limit512 MBACM48 is one of the most popular dance vocal units in Japan. This winter ACM48 is planning a world concert tour, and you have joined the tour as a camera engineer.
Your job is to write the software that controls a camera on the stage. Treat the stage as a two dimensional plane. The software can rotate the camera to any direction, but it cannot change the position of the camera.
During a performance each member of ACM48 moves along her own route and sings the parts assigned to her. A route is given as a polygonal line. A member leaves the first point at time 0 and moves along each segment at a constant speed, reaching the j-th point at time tj. After she reaches the last point she stays there.
The camera has to stay on one member for the whole performance. You may change the member the camera follows at time t if and only if the current member and the next member are in the same direction from the camera at that moment, that is, both of them are on the same ray whose endpoint is the camera.
Compute the maximum total time during which the camera is on a member who is singing.
You may assume the following.
The input contains several datasets. Each dataset has the following format.
N
cx cy
The information of the 1-st member
...
The information of the N-th member
N (1≤N≤50) is the number of members, and (cx,cy) is the position of the camera. The information of the N members follows. The information of the i-th member has the following format.
Mi
xi,1 yi,1 ti,1
...
xi,Mi yi,Mi ti,Mi
Li
bi,1 ei,1
...
bi,Li ei,Li
Mi (1≤Mi≤100) is the number of points on the route of the i-th member, and (xi,j,yi,j) is the j-th point of that route. ti,j is the time at which the i-th member reaches the j-th point, where ti,1=0 and ti,j<ti,j+1≤103. Li (0≤Li≤100) is the number of vocal parts of the i-th member, and bi,k and ei,k (0≤bi,k<ei,k<bi,k+1<ei,k+1≤103) are the beginning time and the ending time of her k-th vocal part.
All the input values are integers, and the absolute value of every coordinate is at most 103. A line holding N=0 ends the input. Do not process it as a dataset.
For each dataset print on one line the maximum time that the camera can be focused on singing members. Print the value rounded to exactly six digits after the decimal point.