POJ1422 Air Raid "binary min Path overlay"

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.