Topic Links:
http://poj.org/problem?id=1422
Main topic:
There are n locations and m bars to the street, now to put some paratroopers on the point, paratroopers can walk down the street until they can't go.
Each side can only be walked once by a paratrooper. Q: At least how many paratroopers to put in, so that paratroopers can go to all the points on the map.
Ideas:
It is obvious that the minimum path coverage problem. First convert to two, the n points each point is split into two points, the left is a 1~n point, right
The Edge is also a 1~n point. There will be an edge to the street that points to the right point to the left.
Because the minimum path of the binary graph is covered by the maximum matching number of points-two, the result is the minimum number of paratroopers to be put.
AC Code:
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio>using namespace std;const int maxn = 140;bool map[maxn][maxn],mask[maxn];int nx,ny;int cx[maxn],cy[maxn];int FindPath (int u) {for (int i = 1; I <= NY; ++i) {if (Map[u][i] &&! Mask[i]) {mask[i] = 1; if (cy[i] = =-1 | | Findpath (Cy[i])) {Cy[i] = u; Cx[u] = i; return 1; }}} return 0;} int Maxmatch () {for (int i = 1; I <= NX; ++i) cx[i] = 1; for (int i = 1; I <= NY; ++i) cy[i] = 1; int res = 0; for (int i = 1; I <= NX; ++i) {if (cx[i] = = 1) {for (int j = 1; j <= NY; ++j) MASK[J] = 0; Res + = Findpath (i); }} return res;} int main () {int t,n,m,u,v; scanf ("%d", &t); while (t--) {memset (map,0,sizeof (MAP)); scanf ("%d%d", &n,&m); for (int i = 1; i<= M; ++i) {scanf ("%d%d", &u,&v); MAP[U][V] = 1; } NX = NY = N; printf ("%d\n", N-maxmatch ()); } return 0;}
POJ1422 Air Raid "binary min Path overlay"