#P4633. Maximum Polygon Containment Depth

    ID: 17879 Type: Default 1000ms 256MiB

Maximum Polygon Containment Depth

Maximum Polygon Containment Depth

Given n non-intersecting polygons whose edges are parallel to the coordinate axes, determine the maximum depth among the polygons. For each polygon i, its depth d_i is defined as

$$ d_i = \max\{d_j\}+1, \quad \text{for all polygons } j \text{ that contain polygon } i. \quad \text{If no polygon contains } i, \; d_i=1. $$

Output the maximum depth among all polygons.

Note: Two polygons do not have any intersecting points. Each polygon is given by its vertices in order (either clockwise or anticlockwise). It is guaranteed that every polygon's edges are vertical or horizontal.

inputFormat

The input begins with an integer n which denotes the number of polygons. For each polygon:

  • An integer m is provided, representing the number of vertices of the polygon.
  • Then, m lines follow, each containing two space-separated integers representing the x and y coordinates of a vertex.

All polygons are simple and non-intersecting, and their edges are either horizontal or vertical.

outputFormat

Output a single integer, which is the maximum depth among all given polygons.

sample

1
4
0 0
0 1
1 1
1 0
1