HDU 12,812 residual augmentation of graphs

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=1281

Each row has a maximum of one car per column, so you can think of the line number and column number as a point, given the point as the maximum match of the edge, the answer is the maximum number of places to be

Then, the important point-the question of whether the maximum number of matches to be converted to deleted edges is changed

The easy-to-know point must be the edge in the model that produces the maximum match, so we enumerate the edges and try to delete the judgment.

It is better to mark two labels as mismatched when deleting edges, and then disable this edge to augment on the original basis, if no new augmented path is found, the key points +1, the two markers are restored

If we find a new augmented path, we get a maximum match, and we don't have two labels restored.

After disabling the edge, the next edge is enumerated

#include <cstdio>#include<cstring>#include<algorithm>using namespacestd;Const intmaxn=208;structfuck{intV,next;} EDGE[MAXN*MAXN];intTol;intHEAD[MAXN];voidinit () {tol=0; memset (Head,-1,sizeof(head));}voidAddedge (intUintv) {EDGE[TOL].V=v; Edge[tol].next=Head[u]; Head[u]=tol++;}intPRE[MAXN];intBIAN[MAXN];BOOLVIS[MAXN];BOOLban[maxn*MAXN];BOOLUSED[MAXN];BOOLFindintu) {    inti,v;  for(i=head[u];i!=-1; i=Edge[i].next) {v=edge[i].v; if(vis[v]| | Ban[i])Continue; VIS[V]=true; if(pre[v]==-1||find (Pre[v])) {Pre[v]=T; BIAN[V]=i; return true; }    }    return false;}intHungaryintN) {    inti,ans=0; memset (PRE,-1,sizeof(pre));  for(i=1; i<=n;i++) {memset (Vis,false,sizeof(VIS)); if(Find (i)) ans++; }    returnans;}BOOLckintN) {    intu;  for(u=1; u<=n;u++)    {        if(Used[u])Continue; memset (Vis,false,sizeof(VIS)); if(Find (U)) {Used[u]=true; return true; }    }    return false;}intMain () {inti,j,n,m,k,u,v; intcas=1;  while(SCANF ("%d%d%d", &n,&m,&k) = =3) {init ();  for(i=1; i<=k;i++) {scanf ("%d%d",&u,&v); Addedge (U,v+N); } memset (Ban,false,sizeof(ban)); intans=Hungary (n); intsum=0; memset (Used,false,sizeof(used));  for(j=n+1; j<=n+m;j++)if(pre[j]!=-1) used[pre[j]]=true;  for(i=n+1; i<=n+m;i++)        {            if(pre[i]==-1)Continue; intBitch=Bian[i]; intshit=Pre[i]; Ban[bian[i]]=true; Pre[i]=-1; Used[shit]=false; if(!ck (n)) {Sum++; Pre[i]=shit; Used[shit]=true; } Ban[bitch]=false; } printf ("Board%d has%d important blanks for%d chessmen.\n", cas++, Sum,ans); }    return 0;}

HDU 12,812 residual augmentation of graphs

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.