#K82377. Minimum Towers to Cover Enemies
Minimum Towers to Cover Enemies
Minimum Towers to Cover Enemies
You are given a grid of m rows and n columns with e enemies positioned on it. A tower, when placed along a row or a column, can cover all enemies in that row or column. Your task is to determine the minimum number of towers needed so that every enemy is within the attack range of at least one tower.
This is mathematically equivalent to finding the minimum between the number of unique rows and the number of unique columns that contain at least one enemy, i.e. \( \min(\text{# unique rows},\; \text{# unique columns} ) \).
inputFormat
The input is read from standard input (stdin). The first line contains three space-separated integers: m, n, and e, representing the number of rows, columns, and enemies respectively. This is followed by e lines, each containing two space-separated integers r and c, indicating the enemy's position (row and column).
outputFormat
Output a single integer to standard output (stdout) which is the minimum number of towers required to cover all the enemies.
## sample5 4 3
1 2
3 4
5 2
2