Under construction

Still being built. Things may change

March of the Penguins

Time limit5sMemory limit128 MB

Summary
Determine, for each candidate ice floe, whether a max-flow feasibility check (respecting per-floe departure jump capacities and distance-limited edges) allows all penguins from every floe to reach it.
Level

Medium7 of 10

Topics
Graph, Greedy, Math
Solved
No attempts yet

Problem

Several penguins live on a glacier field in Antarctica. Each penguin stands on one of many ice floes drifting on the sea. A single floe may hold several penguins, and some floes may hold none at all.

Penguins are highly social, so they all want to gather on one floe. To do this they pick one floe as the destination and jump from floe to floe until every penguin has gathered there. Penguins cannot fly, however, so they cannot reach a floe that is too far away: a penguin may jump between two floes only if the Euclidean distance between them is at most DD.

Because of global warming the floes are melting, and some crack and sink after being used too many times. The penguins are experts on ice and know exactly how many jumps each floe can bear. When a penguin jumps from one floe to another, the floe it leaves (was standing on) is damaged once, while the floe it lands on is not. In other words, at most mim_i jumps may depart from floe ii.

Determine every floe on which all the penguins can gather.

Input

The first line contains the number of test cases TT (T≤100T \le 100).

Each test case is given as follows.

  • The first line contains the number of floes NN (1≤N≤1001 \le N \le 100) and the maximum jump distance DD (0≤D≤1000000 \le D \le 100000). DD may be a real number.
  • Each of the next NN lines contains xix_i, yiy_i, nin_i, mim_i.
    • xix_i, yiy_i: the coordinates of the floe (−10000≤xi,yi≤10000-10000 \le x_i, y_i \le 10000)
    • nin_i: the number of penguins standing on that floe (0≤ni≤100 \le n_i \le 10)
    • mim_i: the maximum number of jumps that may depart from that floe (1≤mi≤2001 \le m_i \le 200)

Floes are numbered from 00 in the order they are given.

Output

For each test case, print on one line the numbers of all floes on which every penguin can gather, in ascending order and separated by spaces. If no floe allows all penguins to gather, print −1-1 on that line instead.

Examples3

  1. Example 1

    Input
    2
    5 3.5
    1 1 1 1
    2 3 0 1
    3 5 1 1
    5 1 1 1
    5 4 0 1
    3 1.1
    -1 0 5 10
    0 0 3 9
    2 0 1 1
    
    Expected output
    1 2 4
    -1
    
  2. Example 2

    Input
    1
    1 0
    0 0 3 1
    
    Expected output
    0
    
  3. Example 3

    Input
    1
    2 5.0
    0 0 2 5
    3 0 2 5
    
    Expected output
    0 1