This page is still under construction.

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

The Islands

Time limit3sMemory limit128 MB

Summary
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 00;
  • Byteotia, the outermost island, has degree 11;
  • a lake lying on an island of degree ii has degree i+1i+1;
  • an island lying on a lake of degree ll has degree l+1l+1.

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 xx- or yy-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 nn, the number of coastlines, 1≤n≤400001 \le n \le 40000.

Each of the next nn lines describes one coastline. A line begins with an even integer kk, the number of vertices of that coastline, 4≤k≤100004 \le k \le 10000, followed by kk integers x1,x2,…,xkx_1, x_2, \dots, x_k with 0≤xi≤1080 \le x_i \le 10^8. The vertices of the coastline are

(x1,x2),(x3,x2),(x3,x4),(x5,x4),…,(xk−1,xk),(x1,xk),(x_1,x_2),(x_3,x_2),(x_3,x_4),(x_5,x_4),\dots,(x_{k-1},x_k),(x_1,x_k),

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 200000200000 vertices in total.

Output

Output a single integer: the maximum degree of any island or lake.

Hint

Examples7

  1. Example 1

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

    Input
    1
    4 0 0 10 10
    
    Expected output
    1
    
  3. Example 3

    Input
    3
    4 0 0 100 100
    4 10 10 90 90
    4 20 20 80 80
    
    Expected output
    3
    
  4. Example 4

    Input
    2
    4 0 0 10 10
    4 20 20 30 30
    
    Expected output
    1
    
  5. Example 5

    Input
    5
    4 0 0 100 100
    4 5 5 95 95
    4 10 10 90 90
    4 15 15 85 85
    4 20 20 80 80
    
    Expected output
    5
    
  6. Example 6

    Input
    4
    4 0 0 100 100
    4 10 10 40 40
    4 60 60 90 90
    4 15 15 35 35
    
    Expected output
    3
    
  7. Example 7

    Input
    6
    4 0 0 200 200
    4 10 10 190 190
    4 20 20 80 80
    4 120 20 180 80
    4 30 30 70 70
    4 130 30 170 70
    
    Expected output
    4