POJ 3041 Hungarian algorithm template problem

Source: Internet
Author: User

The first preview is Baidu's algorithm and then learn a bit

And then found a senior's PPT and learned a bit.

Found.. It's not the same.

I have tried to find a template problem. Baidu's bad use is WA, anyway. Sure enough, you should follow the seniors.

The points on each side of the graph are the number of rows and columns

Each one has a point where the ranks are connected to one side.

Ask for the minimum point coverage

And then stuck ... Later saw the increase Lin's blog ...

Minimum point overwrite = maximum number of matches is a template problem.

Then WA.

It was later discovered that when the left-hand side of the loop was to be mem once a vis array

It should be re-emptied before each search. Or how to find it next time ... Is it not necessary to be visited by the road to the point?

#include <stdio.h> #include <string.h> #include <algorithm> #include <map> #include <math.h >using namespace Std;int s[505][505];int vis[505];int n,m;int link[505];bool Find (int i) {for    (int k=1;k<=n;k+ +)    {        if (s[i][k]==1&&vis[k]==0)        {            vis[k]=-1;            if (link[k]==-1| | Find (Link[k]))            {                link[k]=i;                return true;}}    }    return false;} int main () {while (~scanf ("%d%d", &n,&m)) {    memset (s,0,sizeof (s));    memset (link,-1,sizeof (link));    for (int i=1;i<=m;i++)    {        int a, b;        scanf ("%d%d", &a,&b);        s[a][b]=1;    }    int ans=0;    for (int i=1;i<=n;i++)    {        memset (vis,0,sizeof (Vis));        if (find (i))        {            ans++;        }    }    printf ("%d\n", ans);}}

  

POJ 3041 Hungarian algorithm template problem

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.