atcoder#ABC269D. [ABC269D] Do use hexagon grid
[ABC269D] Do use hexagon grid
Score : points
Problem Statement
We have an infinite hexagonal grid shown below. Initially, all squares are white.
A hexagonal cell is represented as with two integers and . Cell is adjacent to the following six cells:
Takahashi has painted cells black. Find the number of connected components formed by the black cells. Two black cells belong to the same connected component when one can travel between those two black cells by repeatedly moving to an adjacent black cell.
Constraints
- All values in the input are integers.
- The pairs are distinct.
Input
The input is given from Standard Input in the following format:
Output
Print the answer as an integer.
6
-1 -1
0 1
0 2
1 0
1 2
2 0
3
After Takahashi paints cells black, the grid looks as shown below.
The black squares form the following three connected components:
4
5 0
4 1
-3 -4
-2 -5
4
5
2 1
2 -1
1 0
3 1
1 -1
1