The Islands
Time limit3sMemory limit128 MB
Given nested rectilinear coastlines listed parent-before-child, find the maximum nesting depth among islands and lakes.
- Level
Medium7 of 10
- Topics
- Geometry, Sorting, Implementation
- Solved
- No attempts yet
Problem
Byteotia is an island surrounded by the ocean. Byteotia contains lakes; on those lakes there are isles that themselves contain lakes, on which there are further isles, and so on.
We assign a degree to every body of water and every piece of land:
- the ocean has degree ;
- Byteotia, the outermost island, has degree ;
- a lake lying on an island of degree has degree ;
- an island lying on a lake of degree has degree .
Consequently every island has an odd degree, while every lake (and the ocean) has an even degree.
Every lake and every island is bounded by a coastline shaped like a rectilinear polygon: each edge is perpendicular to its neighbours (all edges are parallel to the - or -axis) and every vertex has integer coordinates. No two coastlines touch or cross.
Given all of the coastlines, compute the maximum degree that occurs among the islands and lakes.
Write a program that:
- reads the coastlines of the islands and lakes from standard input,
- computes the maximum degree of any island or lake,
- writes the result to standard output.
Input
The first line contains one integer , the number of coastlines, .
Each of the next lines describes one coastline. A line begins with an even integer , the number of vertices of that coastline, , followed by integers with . The vertices of the coastline are
given in Cartesian coordinates in anticlockwise order (so when walking from one vertex to the next the interior always lies on the left).
The coastlines are listed so that:
- the coastline of every lake appears after the coastline of the island it lies on,
- the coastline of every island appears after the coastline of the lake it lies on.
The whole map is described using at most vertices in total.
Output
Output a single integer: the maximum degree of any island or lake.
Hint
