求助
查看原帖
求助
189912
Novicelpx楼主2021/11/25 19:16

wa的一个点下载数据后发现本地答案比正解少1,t了三个,恳请犇犇赐教

#include<bits/stdc++.h>
using namespace std;
bool mapp[507][507],can[507][507];
int ans,match[507];
int n,m,e;
bool dfs(int left){
	for(int i=1;i<=m;i++){
		if(mapp[left][i]&&can[left][i]==0){
			if(match[i]==0){
				can[left][i]=1;
				match[i]=left;
				return true;
			}
			else{
				if(dfs(match[i])){
					can[left][i]=1;
					match[i]=left;
					return true;
				}
			}
		}
	}
	return false;
}
int main(){
	cin>>n>>m>>e;
	for(int i=1;i<=e;i++){
		int l,r;
		cin>>l>>r;
		mapp[l][r]=1;
	}
	for(int i=1;i<=n;i++){
		if(dfs(i))ans++;
	}
	cout<<ans;
	return 0;
}
2021/11/25 19:16
加载中...