bzoj1191

这是比较久以前的题了,复习匈牙利时翻了出来

板子

#include <stdio.h>
#include <cstring>
using namespace std;
struct node 
{
  int v,next;
}e[10000];
int head[10000],father[10000],n,m,i,res,point=0;
bool v[100000];
bool f(int x)
{
    for(int i=head[x];i!=-1;i=e[i].next)
    {
        if(v[i])continue;
        v[i]=true;
        if(!father[e[i].v]||f(father[e[i].v]))
        {
            father[e[i].v]=x;
            return true;
        }
    }
    return false;
}
void add(int u,int v)
{
  e[++point].v=v;
  e[point].next=head[u];
  head[u]=point;
}
int main()
{
  memset(head,-1,sizeof(head));
  memset(father,0,sizeof(father));
  int a,b;
  scanf("%d%d",&n,&m);
  for(i=1;i<=m;i++)
  {
    scanf("%d%d",&a,&b);
    add(i,a);
    add(i,b);
  }
  for(i=1;i<=m;i++)
  {
    memset(v,false,sizeof(v));
    if(f(i))res++;
    else break;
  }
  printf("%d",res);
  return 0;
}
View Code
原文地址:https://www.cnblogs.com/new-hand/p/7726649.html