Polygon Count
Time limit2sMemory limit128 MB
Given up to 60 integer-coordinate segments drawn on paper, count how many simple closed polygons are formed, excluding faces from crossings and shapes touched by dangling extra edges.
- Level
Hard8 of 10
- Topics
- Geometry, Graph, Union-find
- Solved
- No attempts yet
Problem
Given line segments whose endpoints have integer coordinates, draw all of them on paper. Compute how many polygons are formed using only those segments.
A polygon here means one simple closed figure made from at least three line segments. New regions that appear only because two polygons overlap or cross are not counted as polygons. Only closed figures made directly from the input segments are recognized.
Also, if a line segment that is not part of a closed figure is connected to that figure, the closed figure is not considered a polygon.
Input
The first line contains the number of line segments N, where 1 <= N <= 60.
Each of the next N lines describes one segment. A line contains, in order, the x-coordinate and y-coordinate of one endpoint, followed by the x-coordinate and y-coordinate of the other endpoint.
All coordinates are non-negative integers not greater than 10000.
Output
Print the number of polygons on the first line.