Number of Drawings
Time limit2sMemory limit128 MB
Given T polylines defined by their points, count how many separate connected drawings form when polylines that touch or overlap are merged into one group.
- Level
Medium7 of 10
- Topics
- Geometry, Union-find, Implementation, Math
- Solved
- No attempts yet
Problem
A polyline is a shape made by connecting several points in order with continuous line segments. The endpoint of one segment is the starting point of the next segment.
If two polylines share at least one point, they belong to the same drawing. A shared point may be a vertex, an intersection point on the segments, or any point in an overlapping segment.
Given T polylines, find the number of separate drawings.
Input
The first line contains the number of polylines T.
For each polyline, the first line contains N, the number of points in that polyline. The next N lines contain the point coordinates x y in order.
N may be 1. T is less than 1000, and N is less than 500. Every coordinate is an integer from 0 to 10000, inclusive.
Output
Print the number of drawings on the first line.