//
#include<stdio.h>
#include<vector>
#include<string.h>
#define MaxN 510
using namespace std;
int from[MaxN];
vector<int> g[MaxN];
bool used[MaxN];
bool match(int num)
{
int i;
for(i = 0; i < g[num].size(); i++)
{
if(!used[g[num][i]])
{
used[g[num][i]] = true;
if(from[g[num][i]] == 0 || match(from[g[num][i]]))
{
from[g[num][i]] = num;
return true;
}
}
}
return false;
}
int hungary(int n)
{
int i;
int tot = 0;
memset(from, 0, sizeof(from));
for( i = 1; i <=n; i++)
{
memset(used, 0, sizeof(used));
if(match(i))
tot ++;
}
return tot;
}
//如果要a-b加一条边,则 g[a].push_back(b);
二分图匹配模板
最新推荐文章于 2022-04-21 16:55:24 发布