Under construction

Still being built. Things may change

Goose, Goose, Ducks?

Memory limit1024 MB

Summary
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 MM triples of integers (Xi,Yi,Ci)(X_i, Y_i, C_i). Each triple means the ducks would meet exactly CiC_i seconds after the start of the conference at point (Xi,Yi)(X_i, Y_i), which is XiX_i meters east and YiY_i 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 (x,y)(x, y) at time tt can reach (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 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 jj-th statement was made by attendee AjA_j, who claimed that both AjA_j and attendee BjB_j were at point (Uj,Vj)(U_j, V_j) exactly DjD_j 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 HH is a partition of all attendees into a set of ducks (HH-ducks) and a set of geese (HH-geese). HH is consistent with a set of statements SS if every attendee has a path moving at most 1 meter per second such that:

  • all HH-ducks are at all duck meetings, and
  • for each statement in SS claiming that AA saw BB at point PP at time TT, the paths of both AA and BB pass through PP at time TT.

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

  • HH-ducks is not empty, so at least one duck exists,
  • the statements in SS made by HH-geese are consistent with HH, so geese tell the truth, and
  • for each statement s∈Ss \in S made by an HH-duck, let PP be the set of statements made by HH-geese before ss. Then there is some hypothesis H′H', which may or may not equal HH, such that {s}∪P\{s\} \cup P is consistent with H′H'. 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 HH-ducks over all feasible hypotheses HH.

Input

The first line contains the number of test cases TT. Each test case starts with a line containing three integers NN, MM, and SS, the numbers of attendees, duck meetings, and statements.

The next MM lines each contain three integers XiX_i, YiY_i, and CiC_i. This means there was a duck meeting at point (Xi,Yi)(X_i, Y_i), exactly CiC_i seconds after the start of the conference.

The last SS lines of the test case each describe a statement with five integers AjA_j, BjB_j, UjU_j, VjV_j, and DjD_j. Attendee AjA_j stated that AjA_j and BjB_j were both at point (Uj,Vj)(U_j, V_j) exactly DjD_j 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 xx is the test case number starting from 1 and yy is the minimum number of ducks that might have infiltrated the conference.

Constraints

  • 1≤T≤501 \le T \le 50.
  • −109≤Xi≤109-10^9 \le X_i \le 10^9 for all ii.
  • −109≤Yi≤109-10^9 \le Y_i \le 10^9 for all ii.
  • 1≤Ci≤1091 \le C_i \le 10^9 for all ii.
  • Ci<Ci+1C_i < C_{i+1} for all ii.
  • (Xi−Xi+1)2+(Yi−Yi+1)2≤(Ci−Ci+1)2(X_i - X_{i+1})^2 + (Y_i - Y_{i+1})^2 \le (C_i - C_{i+1})^2 for all ii.
  • 1≤Aj≤N1 \le A_j \le N for all jj.
  • 1≤Bj≤N1 \le B_j \le N for all jj.
  • Aj≠BjA_j \ne B_j for all jj.
  • −109≤Uj≤109-10^9 \le U_j \le 10^9 for all jj.
  • −109≤Vj≤109-10^9 \le V_j \le 10^9 for all jj.
  • 1≤Dj≤1091 \le D_j \le 10^9 for all jj.
  • (Aj,Bj,Uj,Vj,Dj)≠(Ak,Bk,Uk,Vk,Dk)(A_j, B_j, U_j, V_j, D_j) \ne (A_k, B_k, U_k, V_k, D_k) for all j≠kj \ne k.

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.

Examples1

  1. Example 1

    Input
    2
    2 1 2
    1 2 3
    1 2 1 1 1
    2 1 2 2 2
    4 2 4
    4 3 10
    -4 -3 20
    1 3 4 3 11
    2 4 0 0 16
    3 1 6 3 9
    4 2 0 0 16
    
    Expected output
    Case #1: 1
    Case #2: 2