This page is still under construction.

Parts of this page are still being built. What you see may change.

Pahom on Water

Time limit1sMemory limit128 MB

Summary
Decide whether Pahom can travel from the red pad to the violet pad and back, stepping only to strictly higher frequencies outbound and strictly lower ones inbound, with each non-red pad vanishing after he leaves it.
Level

Hard8 of 10

Topics
Graph, DFS, Backtracking, Geometry
Solved
No attempts yet

Problem

Pahom on Water is an interactive game inspired by a short story of Leo Tolstoy about a poor man whose greed for land costs him everything. The starting screen shows a number of circular pads, each painted with a colour from the visible-light spectrum. A colour is identified by its frequency (in THz). Several pads may share the same colour, except for red and violet: there is exactly one red pad (the lowest frequency, 400 THz) and exactly one violet pad (the highest frequency, 789 THz).

Two pads may overlap, and one pad may even fully contain another pad of a different colour, but two pads never merely touch at their boundary. Pahom starts on the red pad.

The goal is to walk Pahom from the red pad to the violet pad and then back to the red pad, obeying these rules:

  1. While walking from the red pad toward the violet pad, Pahom may step from pad α\alpha to pad β\beta if they share a common overlapping region and the frequency of α\alpha is strictly less than the frequency of β\beta.
  2. While walking back from the violet pad toward the red pad, Pahom may step from pad α\alpha to pad β\beta if they share a common overlapping region and the frequency of α\alpha is strictly greater than the frequency of β\beta.
  3. Every coloured pad except the red pad disappears the moment Pahom steps off it.

For each game instance, decide whether at least one full round trip (red → violet → red) is possible.

Input

The first line contains an integer KK (1≤K≤501 \le K \le 50), the number of game instances. Each instance begins with a line containing an integer NN (2≤N≤3002 \le N \le 300), the number of pads, followed by NN lines, one per pad. Each pad line contains the colour frequency, the xx- and yy-coordinates of the pad's centre, and the pad's radius, separated by single spaces.

The frequency is a real number with at most three decimal places. The coordinates and the radius are integers given in metres. Every integer value lies in the range −10000-10000 to 1000010000 inclusive. In every instance all frequencies lie between 400.0400.0 and 789.0789.0 inclusive, exactly one pad has frequency 400.0400.0, and exactly one pad has frequency 789.0789.0.

Output

For each instance, print a single line containing Game is VALID if a valid round trip exists, or Game is NOT VALID otherwise.

Examples3

  1. Example 1

    Input
    2
    2
    400.0 0 0 4
    789.0 7 0 2
    4
    400.0 0 0 4
    789.0 7 0 2
    500.35 5 0 2
    500.32 5 0 3
    
    Expected output
    Game is NOT VALID
    Game is VALID
    
  2. Example 2

    Input
    1
    2
    400.0 0 0 5
    789.0 3 0 5
    
    Expected output
    Game is VALID
    
  3. Example 3

    Input
    1
    3
    400.0 0 0 3
    500.0 4 0 2
    789.0 7 0 2
    
    Expected output
    Game is NOT VALID