Flood
Time limit1sMemory limit128 MB
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 points in the coordinate plane and 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.
Write a program that, given the coordinates of the points and the descriptions of the walls, determines which walls are still standing after the flood.
Input
The first line contains an integer (), the number of points.
Each of the next lines contains two integers and (), the coordinates of one point. The points are numbered from to in the order given, and no two points have the same coordinates.
The next line contains an integer (), the number of walls.
Each of the next lines contains two distinct integers and (), meaning that before the flood a wall connected points and . The walls are numbered from to in the order given.
Output
On the first line, print a single integer , the number of walls still standing after the flood.
On each of the following lines, print the index of one standing wall. Print the indices in increasing order.


