#DSU0000061. Dò mìn phản ứng dây chuyền (Unusual Minesweeper)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Dò mìn phản ứng dây chuyền (Unusual Minesweeper)
Unusual Minesweeper
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are mines at distinct integer coordinates in the plane. Mine is located at and automatically explodes at integer time if it has not exploded earlier.
When a mine explodes, every unexploded mine on the same row or column at distance at most explodes immediately. Newly triggered mines can cause further explosions, and the entire chain reaction takes no additional time. In addition to automatic explosions, you may manually detonate at most one mine at each integer time, starting at time .
Find the earliest integer time by which every mine can have exploded, assuming you choose the times and positions of manual detonations optimally.
Input
The first line contains . The following lines contain .
Output
Print the minimum completion time in integer seconds.
Subtasks
- Subtask 1 (20 points): , , , ; All coordinate pairs are distinct.
- Subtask 2 (30 points): , , , ; All coordinate pairs are distinct.
- Subtask 3 (50 points): , , , ; All coordinate pairs are distinct.
Examples
Input
5 0
0 0 1
0 1 4
1 0 2
1 1 3
2 2 9
Output
2
Explanation
With and distinct positions, no explosion triggers another mine. Manually detonate the mines with deadlines , , and at times , , and , respectively; the other two detonate automatically at times and . Finishing before time is impossible because only two manual detonations can occur by the end of time , while three mines have later automatic explosion times.