Given line segments in the plane, count the maximum number of faces enclosed by them, i.e. bounded regions of their arrangement.
Hard8GeometryGraphDFSImplementationNo attempts yetTime limit2sMemory limit512 MBAll of Farmer Bob's horses are hoarse and may have a cold. Even the pony is a little hoarse. Because of that, every animal on the farm has to be quarantined on its own. To keep the animals apart, Bob owns a set of n fences that no animal can cross. Farmer Alice took all of Bob's fences and dropped them on the plane in arbitrary positions. Bob has no time to rearrange them, so he has to use them where they lie.
Compute how many of Bob's animals he can quarantine. Bob wants to place as many animals as possible inside non-empty regions enclosed by the fences, so that no animal can reach another animal and no animal can escape to infinity.
Each fence is a line segment between two points. No three fences pass through a common point, and no two fences share more than a single point. Fences are allowed to cross each other.
The first line has a single integer n, the number of fences. (1≤n≤1000)
Each of the next n lines has four integers x1, y1, x2, y2. (−109≤x1,y1,x2,y2≤109) The fence is the straight line segment between the endpoints (x1,y1) and (x2,y2), and the two endpoints are different.
Print one line with a single integer c, the maximum number of animals Farmer Bob can quarantine.

The picture shows the third example input. Two vertical fences, two horizontal fences and one diagonal fence enclose four regions.