天天看點

poj3041(二分比對簡單題)

題目連結:http://poj.org/problem?id=3041

asteroids

time limit: 1000ms

memory limit: 65536k

total submissions: 14022

accepted: 7629

description

bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an n x n grid (1 <= n <= 500). the grid contains k asteroids (1 <= k <= 10,000), which are conveniently located at the lattice points of the grid. 

fortunately, bessie has a powerful weapon that can vaporize all the asteroids in any given row or column of the grid with a single shot.this weapon is quite expensive, so she wishes to use it sparingly.given the location of all the asteroids in the field, find

the minimum number of shots bessie needs to fire to eliminate all of the asteroids.

input

* line 1: two integers n and k, separated by a single space. 

* lines 2..k+1: each line contains two space-separated integers r and c (1 <= r, c <= n) denoting the row and column coordinates of an asteroid, respectively.

output

* line 1: the integer representing the minimum number of times bessie must shoot.

sample input

sample output

hint

input details: 

the following diagram represents the data, where "x" is an asteroid and "." is empty space: 

x.x 

.x. 

output details: 

bessie may fire across row 1 to destroy the asteroids at (1,1) and (1,3), and then she may fire down column 2 to destroy the asteroids at (2,2) and (3,2).

source

這也是一道比較簡單的二分比對的題目。把光束當作圖的頂點,而把小行星當作連接配接對應光束的邊,如此一來,光束的攻擊方案即對應一個頂點集合s。圖中每一條邊至少有一個屬于s的端點。轉換成了最小頂點覆寫問題。

在二分圖中     最大比對=最小頂點覆寫

于是用二分比對可解: