Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 17258 |
|
Accepted: 9386 |
Description
Bessie wants to navigate she spaceship through a dangerous asteroid field in the shape of an n x N grid (1 <= N <= 5 ). The grid contains K asteroids (1 <= k <=), which is conveniently located at the lattice points of the G Rid.
Fortunately, Bessie have a powerful weapon that can vaporize all the asteroids on any given row or column of the grid with A single shot. This weapon was quite expensive, so she wishes to use it sparingly. Given the location of the asteroids in the field, find the minimum number of shots Bessie needs to fire to eliminate a ll of the asteroids.
Input
* Line 1:two integers N and K, separated to a single space.
* Lines 2..k+1:each line contains, 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
3 41 11 32 23 2
Sample Output
2
Hint
INPUT DETAILS:
The following diagram represents the data, where "X" is a asteroid and "." is empty space:
x.x
. X.
. X.
OUTPUT DETAILS:
Bessie may fire across row 1 to destroy the asteroids at (all) and (1,3), and then she could fire down column 2 to destroy T He asteroids at (2,2) and (3,2). The problem is to use the maximum matching of the binary graph, each row, each column as a point, all the rows made up of a set of points, and all the columns constitute a set of points, the input data as a connection to the two sets of edges, so that is a two-part diagram.
1#include <iostream>2#include <stdio.h>3#include <string.h>4 using namespacestd;5 intmap[ -][ -];6 intvis[ -],match[ -];7 intM,n;8 intDFS (intp) {9 intv;Ten for(intI=1; i<=m;i++){ One if(map[p][i]&&!Vis[i]) { Avis[i]=1; -v=Match[i]; - if(v==-1||DFS (v)) { thematch[i]=p; - return 1; - } - + } - } + return 0; A } at intMain () { - while(~SCANF ("%d%d",&m,&N)) { -memset (Map,0, -* -*sizeof(int)); - for(intI=0; i<n;i++){ - intb; -scanf"%d%d",&a,&b); inmap[a][b]=1; - } to intresult=0; +memset (match,-1, -*sizeof(int)); - for(intI=1; i<=m;i++){ thememset (Vis,0, -*sizeof(int)); *result+=DFS (i); $ }Panax Notoginsengprintf"%d\n", result); - } the return 0; +}
Asteroids-poj 3041 (The maximum matching problem of binary graph)