#DSU0000022. Các thành phần trên lưới lục giác (Do use hexagon grid)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Các thành phần trên lưới lục giác (Do use hexagon grid)
Do use hexagon grid
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Consider an infinite hexagonal grid. Every cell is identified by a pair of integer coordinates . Unlike a square grid, a cell has exactly six neighboring cells at , , , , and .
Exactly cells at distinct coordinates are black; all other cells are white. Two black cells belong to the same region if one can travel between them through a sequence of black cells, with consecutive cells adjacent in one of the six specified directions. Traveling through white cells is not allowed.
Count the connected regions of black cells. An isolated black cell forms a region on its own.
Input
The first line contains . Each of the following lines contains coordinates of a black cell.
Output
Print the number of connected components.
Subtasks
- Subtask 1 (20 points): ; ; no coordinate pair repeats.
- Subtask 2 (30 points): ; ; no coordinate pair repeats.
- Subtask 3 (50 points): ; ; no coordinate pair repeats.
Examples
Input
6
-1 -1
0 1
0 2
1 0
1 2
2 0
Output
3
Explanation
Cell is isolated; form another component; and form the third.