//#include<bits/stdc++.h>
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#define LL long long
#define Max 100005
const LL mod=1e9+7;
const LL LL_MAX=9223372036854775807;
using namespace std;
int road[505][10005],used[Max];
int match[Max];
int n,k;
bool dfs(int x){
for(int i=1;i<=n;i++)
if(!used[i] && road[x][i]){
used[i]=1;
if(!match[i] || dfs(match[i])){
match[i]=x;
return 1;
}
}
return 0;
}
int main()
{
scanf("%d%d",&n,&k);
int x,y;
for(int i=0;i<k;i++){
scanf("%d%d",&x,&y);
road[x][y]=1;
}
int ans=0;
for(int i=1;i<=n;i++){
memset(used,0,sizeof(used));
if(dfs(i))
ans++;
}
printf("%d\n",ans);
return 0;
}
二分图最大匹配(模板)
最新推荐文章于 2023-09-19 15:58:18 发布