Under construction

Still being built. Things may change

AirDrop

Interview

Time limit1sMemory limit1024 MB

Summary
Find which friends holding a photo Puang can receive, directly or through relay friends within distance K and version gap T.
Level

Medium4 of 10

Topics
Graph, BFS
Solved
No attempts yet

Problem

Puang lives on a two-dimensional plane and has just enrolled at university as a freshman. Being outgoing, Puang made NN friends at university and plans to call them friend 11, friend 22, ⋯\cdots, friend NN.

Puang took photos with some of these friends. Puang wants to receive those photos but finds moving around tiresome, so Puang plans to receive them by AirDrop while sitting still.

AirDrop can send a photo only to a device whose version differs from the sender's phone by at most TT and whose Euclidean distance is at most KK. Even if the version difference between Puang and a friend who holds a photo is greater than TT, Puang can still receive the photo through an indirect path via other friends.

Puang wants to receive as many photos as possible using the NN friends Puang knows. Find every photo Puang can receive.

Input

The first line contains the number of friends NN, the maximum AirDrop distance KK, and the maximum phone version difference TT, separated by spaces.

The second line contains Puang's coordinates and Puang's phone version XpX_p, YpY_p, VpV_p, separated by spaces.

From the third line onward, the next NN lines describe Puang's friends. The ii-th line contains friend ii's information XiX_i, YiY_i, ViV_i, PiP_i, separated by spaces. XiX_i and YiY_i are coordinates, and ViV_i is the phone version. If PiP_i is 0, Puang did not take a photo with friend ii. If PiP_i is 1, Puang took a photo with friend ii.

Output

On the first line, print the numbers of the friends who initially had a photo that Puang can receive, in ascending order, separated by spaces.

If Puang can receive no photos, print 0.

Constraints

  • 1≤N≤3 0001 \le N \le 3\,000
  • 0≤K≤30 0000 \le K \le 30\,000
  • 0≤T≤140 \le T \le 14
  • −10 000≤Xp,Yp,Xi,Yi≤10 000-10\,000 \le X_p, Y_p, X_i, Y_i \le 10\,000
  • 1≤Vp,Vi≤151 \le V_p, V_i \le 15
  • P∈{0,1}P \in \{ 0, 1 \}
  • 1≤i≤N1 \le i \le N
  • All given coordinates are distinct.
  • All given input values are integers.

Examples2

  1. Example 1

    Input
    5 4 3
    5 2 4
    2 2 1 0
    2 5 4 1
    2 8 7 1
    4 9 11 1
    7 6 4 1
    
    Expected output
    2 3
    
  2. Example 2

    Input
    1 4 3
    5 6 4
    2 2 1 1
    
    Expected output
    0