This page is still under construction.

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

Moving Between Circles 2

Time limit1sMemory limit1024 MB

Summary
Given circles with centers on the x-axis and non-intersecting boundaries, count and list the circles on the unique simple path from circle A to circle B, where nested circles let you move directly.
Level

Medium7 of 10

Topics
Tree, DFS, Sorting, Stack
Solved
No attempts yet

Statement

On the coordinate plane there are NN circles whose centers lie on the x-axis. Any two of the NN circles have no intersection point, whether internal or external tangency. One circle may be contained inside another.

You want to move from the interior of one circle to the interior of another. Each circle interior may be visited only once, and you may not visit it twice or more.

For convenience, treat the coordinate plane itself as one circle with center (0, 0) and infinite radius.

When only two circles A and B exist on the coordinate plane, the correct ways to move from the interior of A to the interior of B are as follows.

1. A and B are not nested in each other and do not meet

The first case moves from the interior of A →\rightarrow the coordinate plane →\rightarrow the interior of B. No correct path other than this exists.

2. B is inside A

The second case moves from the interior of A →\rightarrow the interior of B. No correct path other than this exists.

3. A is inside B

The third case also moves from the interior of A →\rightarrow the interior of B. No correct path other than this exists.

The cases below are incorrect moves from the interior of A to B.

4. Circles A, B, C exist on the coordinate plane, are not nested in each other, and do not meet

This path goes from the interior of A →\rightarrow the coordinate plane →\rightarrow the interior of C →\rightarrow the coordinate plane →\rightarrow the interior of B. The coordinate plane is visited twice, so this is not a correct move.

4. Circles A, B exist on the coordinate plane and B is inside A

This path goes from the interior of A →\rightarrow the coordinate plane →\rightarrow the interior of A →\rightarrow the interior of B. The interior of A is visited twice, so this is not a correct move.

Given NN circles on the coordinate plane, find the number of circles visited when moving from the interior of circle A to the interior of circle B.

Input

The first line gives the number of circles NN.

From the second line to the N+1N + 1-th line, the circle number kk, the xx-coordinate of the circle center, and the circle radius rr are given, separated by spaces.

The last line gives the numbers of the two circles AA and BB, separated by a space.

The given circle numbers are all distinct.

The coordinate plane is assumed to have number 0.

Output

On the first line, print the number of circles visited.

On the second line, print the numbers of the visited circles in order, separated by spaces.

Constraints

  • 2≤N≤200,0002 \le N \le 200,000
  • −1,000,000≤x≤1,000,000-1,000,000 \le x \le 1,000,000
  • 1≤r≤10,0001 \le r \le 10,000
  • 1≤A,B≤N1 \le A, B \le N, A≠BA \ne B
  • 1≤k≤N1 \le k \le N
  • x,rx, r are integers

Hint

Relative position of two circles

Use the following to determine the relative position of two circles.

Let the radius of circle A be rAr_A, the radius of circle B be rBr_B, and the distance between the centers of A and B be dd.

Meet at two pointsMeet at one pointDo not meet
Externally tangentInternally tangentExternally separateOne inside the otherConcentric
∥rA−rB∥<d<rA+rB\|r_A-r_B\|<d<r_A+r_BrA+rB=dr_A+r_B=d∥rA−rB∥=d\|r_A-r_B\|=drA+rB<dr_A+r_B<dd<∥rA−rB∥d<\|r_A-r_B\|d=0d=0

Distance between two points

The distance dd between (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) is computed as follows.

d=(x1−x2)2+(y1−y2)2d = \sqrt{(x_1-x_2)^2+(y_1-y_2)^2}

Examples2

  1. Example 1

    Input
    4
    1 5 4
    2 3 1
    3 6 1
    4 13 3
    2 4
    
    Expected output
    4
    2 1 0 4
    
  2. Example 2

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