Goose, Goose, Ducks?

아직 제출이 없습니다메모리 제한1024 MB

문제

The first international Geese conference just wrapped up, and even though it should have been a happy occasion, it was bittersweet. The organizers found a paper with detailed plans of a duck infiltration. Now, they are trying to identify the infiltrating group from among the attendees.

The document that they found contained a list of M\mathbf{M} triples of integers (X_i,Y_i,C_i)(\mathbf{X\_i}, \mathbf{Y\_i}, \mathbf{C\_i}) meaning the ducks would meet exactly C_i\mathbf{C\_i} seconds after the start of the conference at point (X_i,Y_i)(\mathbf{X\_i}, \mathbf{Y\_i}), which is X_i\mathbf{X\_i} meters east and Y_i\mathbf{Y\_i} meters north of the center of the conference floor. Each goose may or may not have been at those specific points at those specific times, but every duck certainly was.

Both ducks and geese walk at a maximum speed of one meter per second, which means an attendee that is at point (x,y)(x, y) at time tt can reach any point of the form (x+Δ_x,y+Δ_y)(x + \Delta\_{x}, y + \Delta\_{y}) by time t+Δ_tt + \Delta\_{t} as long as Δ_x2+Δ_y2Δ_t2{\Delta\_{x}}^2 + {\Delta\_{y}}^2 \le {\Delta\_{t}}^2. Each attendee's position at time 00 can be any point, independently of the other attendees.

After the discovery, the group held a questioning session to try to identify the ducks. During that session, attendees issued a series of statements, one at a time. The jj-th of those, in the order they were issued, was made by attendee A_j\mathbf{A\_j}, claiming that both they and attendee B_j\mathbf{B\_j} were at point (U_j,V_j)(\mathbf{U\_j}, \mathbf{V\_j}) exactly D_j\mathbf{D\_j} seconds after the start of the conference. Points in statements may or may not be points where duck meetings happened.

Statements from geese are always true, but ducks may lie. Moreover, ducks know which attendees are ducks and which are geese. To avoid getting caught easily, ducks only make statements that are consistent with all statements previously made by geese. Note that statements made by geese are consistent with all ducks being at all duck meetings.

It may not be possible to determine all the ducks with the information provided. However, knowing the minimum number of ducks will at least provide a lower bound on the level of duck activity. Note that there was at least one duck. Find this minimum number of ducks.

Formally, a hypothesis HH is a partition of all attendees into a set of ducks (named HH-ducks) and geese (named HH-geese). HH is consistent with a set of statements SS if there exists a path for each attendee moving at most one meter per second such that:

  • all HH-ducks were at all duck meetings and
  • for each statement in SS claiming that AA saw BB at point PP at time TT, both AA and BB⁠'s paths went through point PP at time TT.

A hypothesis HH is feasible under a set of statements SS if:

  • HH-ducks is not empty (i.e., there was at least one duck),
  • the subset of all statements from SS made by members of HH-geese is consistent with HH (i.e., statements from geese are always true), and
  • for each statement sSs \in S made by a member of HH-ducks, if PSP \subseteq S is the subset of statements made by members of HH-geese issued before ss, there exists a hypothesis HH' (which may or may not be equal to HH) such that sP\\{ s \\} \cup P is consistent with HH' (i.e., ducks do not contradict previous statements made by geese).

Notice that the hypotheses HH such that HH-ducks contains all attendees is always feasible.

Find the minimum size of HH-ducks over all feasible hypotheses HH.

입력

The first line of the input gives the number of test cases, T\mathbf{T}. T\mathbf{T} test cases follow. Each test case starts with a line containing three integers, N\mathbf{N}, M\mathbf{M}, and S\mathbf{S}, representing the numbers of attendees, duck meetings, and statements, respectively. The next M\mathbf{M} lines each describe a different duck meeting with three integers X_i\mathbf{X\_i}, Y_i\mathbf{Y\_i}, and C_i\mathbf{C\_i}, representing that there was a meeting at point (X_i,Y_i)(\mathbf{X\_i}, \mathbf{Y\_i}), held exactly C_i\mathbf{C\_i} seconds after the start of the conference. Then, the last S\mathbf{S} lines of a test case each describe a statement. The jj-th of these lines describes the jj-th issued statement with five integers A_j\mathbf{A\_j}, B_j\mathbf{B\_j}, U_j\mathbf{U\_j}, V_j\mathbf{V\_j}, and D_j\mathbf{D\_j}, representing that attendee A_j\mathbf{A\_j} stated that they and attendee B_j\mathbf{B\_j} were both at point (U_j,V_j)(\mathbf{U\_j}, \mathbf{V\_j}) exactly D_j\mathbf{D\_j} seconds after the start of the conference.

출력

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is the minimum number of ducks that might have infiltrated the conference.

제한

  • 1T501 \le \mathbf{T} \le 50.
  • 109X_i109-10^9 \le \mathbf{X\_i} \le 10^9, for all ii.
  • 109Y_i109-10^9 \le \mathbf{Y\_i} \le 10^9, for all ii.
  • 1C_i1091 \le \mathbf{C\_i} \le 10^9, for all ii.
  • C_i<C_i+1\mathbf{C\_i} \lt \mathbf{C\_{i+1}}, for all ii.
  • (X_iX_i+1)2+(Y_iY_i+1)2(C_iC_i+1)2(\mathbf{X\_i} - \mathbf{X\_{i+1}})^2 + (\mathbf{Y\_i} - \mathbf{Y\_{i+1}})^2 \le (\mathbf{C\_i} - \mathbf{C\_{i+1}})^2, for all ii.
  • 1A_jN1 \le \mathbf{A\_j} \le \mathbf{N}, for all jj.
  • 1B_jN1 \le \mathbf{B\_j} \le \mathbf{N}, for all jj.
  • A_jB_j\mathbf{A\_j} \ne \mathbf{B\_j}, for all jj.
  • 109U_j109-10^9 \le \mathbf{U\_j} \le 10^9, for all jj.
  • 109V_j109-10^9 \le \mathbf{V\_j} \le 10^9, for all jj.
  • 1D_j1091 \le \mathbf{D\_j} \le 10^9, for all jj.
  • (A_j,B_j,U_j,V_j,D_j)(A_k,B_k,U_k,V_k,D_k)(\mathbf{A\_j}, \mathbf{B\_j}, \mathbf{U\_j}, \mathbf{V\_j}, \mathbf{D\_j}) \ne (\mathbf{A\_k}, \mathbf{B\_k}, \mathbf{U\_k}, \mathbf{V\_k}, \mathbf{D\_k}), for all jkj \ne k.

힌트

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. Note that there is at least one duck, so all attendees being geese is not feasible.