Under construction

Still being built. Things may change

Dalgona

Time limit1sMemory limit1024 MB

Summary
Given circles and simple polygons on a plane, count the number of regions the shapes divide the plane into.
Level

Medium7 of 10

Topics
Geometry, Graph, Union-find
Solved
No attempts yet

Problem

A dalgona machine has been installed in Lab 512 of building K at Sogang University. Next to the machine are molds in the shape of circles or simple polygons, used for the candy-pulling game. Generally, the shape of the mold determines how hard the game is. However, none of these shapes satisfies Sangwon, the master of the game. The game was too easy, so Sangwon came up with a way to make it harder. If several molds are stamped into one candy, the number of pieces to pull out increases, making the game harder!

Given circles and simple polygons on a two-dimensional plane, write a program that finds the number of regions into which they divide the plane.

Figure 1: The candy shape for the first sample.

Input

The input is given as follows.

NN

poly_1poly\_1

poly_2poly\_2

......

poly_Npoly\_N

  • poly_ipoly\_i is the description of each shape.

    • For a circle, poly_ipoly\_i is given in the following form.

      1 x y r1 \ x \ y \ r

      • A circle with center (x, yx,\ y) and radius rr. (−10 000≤x, y≤10 000, 1≤r≤10 000-10\,000 \le x,\ y \le 10\,000,\ 1 \le r \le 10\,000)
    • For a simple polygon, poly_ipoly\_i is given in the following form.

      m x_1 y_1 x_2 y_2 ... x_m y_mm \ x\_1 \ y\_1 \ x\_2 \ y\_2 \ ... \ x\_m \ y\_m

      • mm is the number of vertices of the simple polygon.
      • (x_i, y_ix\_i,\ y\_i) are the coordinates of each vertex. (−10 000≤x_i, y_i≤10 000-10\,000 \le x\_i,\ y\_i \le 10\,000)
      • The vertices are given in counterclockwise order.

Output

Print the number of regions that the shapes divide the plane into.

Constraints

  • NN is the number of shapes. (1≤N≤2 0001 \le N \le 2\,000)
  • The sum of the number of edges of all simple polygons and the number of circles does not exceed 2 0002\,000.
  • No point lies on three or more circles or edges.
  • All numbers in the input are integers.

Examples3

  1. Example 1

    Input
    6
    7 3 5 1 2 2 2 0 -2 6 -2 4 2 5 2
    4 2 0 2 -4 4 -4 4 0
    1 16 2 2
    7 20 0 12 0 14 -2 14 -6 16 -4 18 -6 18 -2
    1 13 8 2
    1 10 8 3
    
    Expected output
    9
    
  2. Example 2

    Input
    4
    4 750 250 -750 250 -750 -250 750 -250
    1 0 0 250
    1 500 0 250
    1 -500 0 250
    
    Expected output
    12
    
  3. Example 3

    Input
    6
    1 1 1 1
    1 1 1 2
    1 0 1 1
    1 2 1 1
    1 6 1 1
    3 7 2 5 2 5 0
    
    Expected output
    14