萌新求助
查看原帖
萌新求助
171513
Polariserist楼主2020/12/2 07:44
#include<bits/stdc++.h>
using namespace std;
const int maxn=10001;
int n,m,e,edge[maxn][maxn],p[maxn];
bool v[maxn];
bool match(int x){
	for(int i=1;i<=n;i++){
		if(edge[x][i]&&(!v[i])){
			v[i]=1;
			if((!p[i])||match(p[i])){
				p[i]=x;
				return 1;
			}
		}
	}
	return 0;
}
int hungarian(){
	int cnt=0;
	for(int i=1;i<=m;i++){
		memset(v,0,sizeof(v));
		if(match(i)){
			cnt++;
		}
	}
	return cnt;
}
int main(){
	cin>>n>>m>>e;
	for(int i=1;i<=e;i++){
		int x,y;
		cin>>x>>y;
		edge[x][y]=1;
		edge[y][x]=1;
	}
	cout<<hungarian();
}

30pts求助

2020/12/2 07:44
加载中...