#P15510. [CEOI 2014] The Forest of Fangorn

[CEOI 2014] The Forest of Fangorn

Description

Since entering Fangorn Forest, Gimli the dwarf feels uncomfortable. There is something wrong with the trees here! Therefore, Gimli wants to reach one of the camps at the edge of the forest. However, in order to feel safe, at any time Gimli needs to see all trees. Fortunately, dwarves have very good eyes: they can see infinitely far and into every direction.

Fangorn Forest forms a rectangle FF, with sides parallel to the axes of the coordinate system, and with corners at points (0,0)(0,0) and (w,h)(w,h). All NN trees in the forest lie in the interior of FF, and all CC camps (numbered from 11 to CC) lie on the sides of FF. Any tree grows straight upwards (“out of the map”), and can be considered a point. Thus, Gimli sees a tree from his position if and only if no other tree lies on the line segment connecting his position and the tree.

From any camp Gimli can see all trees. At the beginning he is located in the interior of the forest, but not on a tree’s position (dwarves do not climb trees), and he can see all camps and all trees. Since the Forest of Fangorn is very old, there are no three trees lying on a common line.

Gimli can safely reach a camp cc, if there is a path γ\gamma from his original position to cc such that from any point of γ\gamma he can see all trees. Help Gimli by writing a program that finds all the camps he can safely reach.

Input Format

The first line contains two integers ww and hh that indicate the size of the rectangle FF, as described above. The second line contains two integers xGx_G and yGy_G, the coordinates of Gimli’s initial position.

The third line contains an integer CC, the number of camps. The following CC lines describe the camps; the ii-th of these lines contains two integers xix_i and yiy_i, the coordinates of camp number ii.

The line after that contains an integer NN, the number of trees. The following NN lines describe the trees; each of these lines contain two integers xx and yy, the coordinates of a tree. No two of these lines are identical.

Output Format

The first line should contain the number mm of camps Gimli can safely reach. If m0m \neq 0, the next line should contain the numbers of these camps in increasing order.

9 4
1 2
3
7 4
1 4
0 2
4
1 1
6 1
3 3
8 3
2
1 3
9 4
1 2
1
8 4
4
1 1
6 1
3 3
4 3
0

Hint

The situation of the first testcase together with possible paths from Gimli’s starting position GG to the (safely) reachable camps:

Note that Gimli is allowed to leave the forest during his path. However, even outside the forest he must see all trees—otherwise he would be able to reach the second camp, too.

Subtasks

For all testcases 3N20003 \leq N \leq 2000, 1C100001 \leq C \leq 10\,000, and 0<w,h1090 < w, h \leq 10^9.

  • Subtask 1 (30 points). N70N \leq 70, C5C \leq 5
  • Subtask 2 (20 points). The trees form the corners of a convex polygon and N200N \leq 200, C5C \leq 5
  • Subtask 3 (30 points). C5C \leq 5
  • Subtask 4 (20 points). No further constraints.