CF1619G Unusual Minesweeper
Description
Polycarp is very fond of playing the game Minesweeper. Recently he found a similar game and there are such rules.
There are mines on the field, for each the coordinates of its location are known ( $ x_i, y_i $ ). Each mine has a lifetime in seconds, after which it will explode. After the explosion, the mine also detonates all mines vertically and horizontally at a distance of $ k $ (two perpendicular lines). As a result, we get an explosion on the field in the form of a "plus" symbol ('+'). Thus, one explosion can cause new explosions, and so on.
Also, Polycarp can detonate anyone mine every second, starting from zero seconds. After that, a chain reaction of explosions also takes place. Mines explode instantly and also instantly detonate other mines according to the rules described above.
Polycarp wants to set a new record and asks you to help him calculate in what minimum number of seconds all mines can be detonated.
Input Format
N/A
Output Format
N/A
Explanation/Hint
Picture from examplesFirst example:
- $ 0 $ second: we explode a mine at the cell $ (2, 2) $ , it does not detonate any other mine since $ k=0 $ .
- $ 1 $ second: we explode the mine at the cell $ (0, 1) $ , and the mine at the cell $ (0, 0) $ explodes itself.
- $ 2 $ second: we explode the mine at the cell $ (1, 1) $ , and the mine at the cell $ (1, 0) $ explodes itself.
Second example:
- $ 0 $ second: we explode a mine at the cell $ (2, 2) $ we get:
- $ 1 $ second: the mine at coordinate $ (0, 0) $ explodes and since $ k=2 $ the explosion detonates mines at the cells $ (0, 1) $ and $ (1, 0) $ , and their explosions detonate the mine at the cell $ (1, 1) $ and there are no mines left on the field.