Buggy Satellite
Time limit1sMemory limit128 MB
Each test case gives cities with coordinates and a list of regions; report which region is the outer one.
- Level
Medium4 of 10
- Topics
- Geometry, Implementation
- Solved
- No attempts yet
Problem
Discovery Co., Ltd. builds a satellite equipped with a new kind of intelligent camera. The camera runs special software that detects cities and roads in an image, and it can also detect every region — a connected part of the surface bounded by a series of connected roads and containing no other region inside it. Using this technology, the satellite compresses each picture before transmitting it: the compressed form of a picture is simply the list of city locations together with the list of regions.
The satellite was launched before the software was fully tested, so after a while the team began receiving buggy pictures that contain one extra region: the outer region. The outer region is the region of the plane that encloses every other region, and therefore has infinite area.
Every image that is received has the following properties:
- Every city is connected by roads to at least two other cities.
- There is a path between every pair of cities.
- There is at most one road between any pair of cities.
- Roads never cross one another except at cities.

The figure above shows one received image.
Write a program that reads a buggy image and reports which region is the outer region.
Input
The first line contains a single integer (), the number of test cases. The test cases follow one after another with no blank lines between them.
Each test case is given as follows:
- A line with the number of cities ().
- Then lines, each containing two integers and : the location of a city. Cities are numbered through in the order they are listed.
- A line with the number of regions ().
- Then lines, each describing one region: an integer (the number of cities on that region's boundary) followed by the city numbers, listed in clockwise or counterclockwise order.
Output
For each test case, print a single line containing the number of the region that is the outer region. Regions are numbered through in the order they are given in the input. Print the answers in the same order as the test cases, with no blank lines between them.