Bzoj 1191 hnoi2006 superhero hero bipartite graph maximum match

Source: Internet
Author: User

Given n tips and M questions, one of the two tips can be used for each question. The question must be answered continuously and the maximum number of questions can be answered.

The maximum matching of a bipartite graph. If a problem occurs, the two sides are connected to the given tip, and the Hungary algorithm searches for the augmented path. If the two sides are not found, the break

At first, I practiced a side between two tips, and then I got a second answer ...... Sorry ......

#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define M 1010using namespace std;struct abcd{    int to,next;}table[M<<1];int head[M],tot;int n,m;int result[M],state[M],T;void Add(int x,int y){    table[++tot].to=y;    table[tot].next=head[x];    head[x]=tot;}bool Hungary(int x){    int i;    for(i=head[x];i;i=table[i].next)    {        if(state[table[i].to]==T)            continue;        state[table[i].to]=T;        if( !result[table[i].to] || Hungary(result[table[i].to]) )        {            result[table[i].to]=x;            return true;        }    }    return false;}int main(){    int i,x,y;    cin>>n>>m;    for(i=1;i<=m;i++)    {        scanf("%d%d",&x,&y);        ++x;++y;        Add(i,x);Add(i,y);        ++T;        if( !Hungary(i) )            break;    }    cout<<i-1<<endl;}


Bzoj 1191 hnoi2006 superhero hero bipartite graph maximum match

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.