Contour Lines
Time limit1sMemory limit128 MB
Given sets of axis-parallel polygons, decide whether each set can be ordered so every polygon lies inside the next.
- Level
Medium6 of 10
- Topics
- Geometry, Sorting, Implementation
- Solved
- No attempts yet
Problem
Consider a set of polygons whose sides are all parallel to the coordinate axes. Such a set is called a system of contour lines if all of its polygons can be ordered so that the first polygon contains the second one in its interior, the second polygon contains the third one in its interior, and so on. In other words, the polygons can be arranged as a strictly nested chain in which each polygon lies entirely inside the previous one.
Given several sets of axis-parallel polygons, decide for each set whether it is a system of contour lines.
Write a program that:
- reads the descriptions of several sets of polygons,
- for each set decides whether it is a system of contour lines,
- writes the answers to standard output.
Input
The first line contains one integer (), the number of sets to process. The sets follow.
The first line of each set contains one integer (), the number of polygons in the set. Each of the next lines describes one polygon. Such a line begins with one integer (), the number of vertices of the -th polygon, followed by pairs of integers and () that give the coordinates of the consecutive vertices of the polygon, separated by single spaces.
Every polygon has sides parallel to the coordinate axes, no two adjacent sides are collinear, and the boundary of each polygon does not cross itself.
Output
Print lines. The -th line must contain the word TAK (meaning yes) if the -th set of polygons is a system of contour lines, and NIE (meaning no) otherwise.
Hint
