bzoj1191: [HNOI2006]超级英雄Hero

裸匈牙利。我已经15题1A了(捂脸)

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;

struct node
{
    int x,y,next;
}a[21000];int len,last[11000];
void ins(int x,int y)
{
    len++;
    a[len].x=x;a[len].y=y;
    a[len].next=last[x];last[x]=len;
}

int match[11000];
bool v[11000];
bool findmuniu(int x)
{
    for(int k=last[x];k;k=a[k].next)
    {
        int y=a[k].y;
        if(v[y]==false)
        {
            v[y]=true;
            if(match[y]==0||findmuniu(match[y])==true)
            {
                match[y]=x;
                return true;
            }
        }
    }
    return false;
}

int main()
{
    int n,m,x;
    scanf("%d%d",&n,&m);
    len=0;memset(last,0,sizeof(last));
    for(int i=1;i<=m;i++)
    {
        scanf("%d",&x);ins(i,x+1);
        scanf("%d",&x);ins(i,x+1);
    }
    
    memset(match,0,sizeof(match));
    for(int i=1;i<=m;i++)
    {
        memset(v,false,sizeof(v));
        if(findmuniu(i)==false)
        {
            printf("%d
",i-1);
            return 0;
        }
    }
    printf("%d
",m);
    return 0;
}
原文地址:https://www.cnblogs.com/AKCqhzdy/p/8425178.html