This page is still under construction.

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

Flood

Time limit1sMemory limit128 MB

Summary
Given a non-crossing grid-aligned wall network, determine which walls survive after water bursts outward-inward hour by hour until all regions flood.
Level

Hard8 of 10

Topics
Graph, BFS, Geometry, Simulation
Solved
No attempts yet

Problem

In 1964, a catastrophic flood struck a city. Water pushed against the walls and destroyed many buildings. In this task you are given a simplified model of the city just before the flood, and you must determine which walls are left standing after the water has flooded everything.

The model consists of NN points in the coordinate plane and WW walls. Each wall joins a pair of points and passes through no other point. The model also has the following properties:

  • No two walls cross or overlap, though they may touch at their endpoints.
  • Every wall is parallel to either the horizontal or the vertical axis.

Initially the whole plane is dry. At time zero, water instantly floods the exterior (all space not enclosed by walls). After exactly one hour, every wall that has water on one side and air on the other bursts under the water pressure. Water then floods the newly exposed regions. New walls may now have water on one side and air on the other; after another hour those walls also burst, and water spreads further. This process repeats until water has flooded the entire plane.

The figure below illustrates the process.

The state at time zero. Shaded cells are flooded; white cells are dry (air).The state after one hour.The state after two hours. Water has flooded the entire area, and the 4 remaining walls can no longer be broken.

Write a program that, given the coordinates of the NN points and the descriptions of the WW walls, determines which walls are still standing after the flood.

Input

The first line contains an integer NN (2≤N≤1000002 \le N \le 100000), the number of points.

Each of the next NN lines contains two integers XX and YY (0≤X,Y≤10000000 \le X, Y \le 1000000), the coordinates of one point. The points are numbered from 11 to NN in the order given, and no two points have the same coordinates.

The next line contains an integer WW (1≤W≤2N1 \le W \le 2N), the number of walls.

Each of the next WW lines contains two distinct integers AA and BB (1≤A,B≤N1 \le A, B \le N), meaning that before the flood a wall connected points AA and BB. The walls are numbered from 11 to WW in the order given.

Output

On the first line, print a single integer KK, the number of walls still standing after the flood.

On each of the following KK lines, print the index of one standing wall. Print the indices in increasing order.

Examples2

  1. Example 1

    Input
    15
    1 1
    8 1
    4 2
    7 2
    2 3
    4 3
    6 3
    2 5
    4 5
    6 5
    4 6
    7 6
    1 8
    4 8
    8 8
    17
    1 2
    2 15
    15 14
    14 13
    13 1
    14 11
    11 12
    12 4
    4 3
    3 6
    6 5
    5 8
    8 9
    9 11
    9 10
    10 7
    7 6
    
    Expected output
    4
    6
    15
    16
    17
    
  2. Example 2

    Input
    9
    0 0
    2 0
    4 0
    4 2
    4 4
    2 4
    0 4
    0 2
    2 2
    12
    1 2
    2 3
    3 4
    4 5
    5 6
    6 7
    7 8
    8 1
    2 9
    9 6
    8 9
    9 4
    
    Expected output
    4
    9
    10
    11
    12