求助
查看原帖
求助
664284
bei_awa楼主2023/7/26 10:23
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
const int MAXN = 1005;
vector<int> graph[MAXN];
int match[MAXN];
bool visited[MAXN];
bool dfs(int u) {
	for (int i = 0; i < graph[u].size(); ++i) {
		int v = graph[u][i];
		if (!visited[v]) {
			visited[v] = true;
			if (match[v] == -1 || dfs(match[v])) {
				match[v] = u;
				return true;
			}
		}
	}
	return false;
}
int maxMatching(int n) {
	int cnt = 0;
	memset(match, -1, sizeof(match));
	for (int i = 0; i < n; ++i) {
		memset(visited, 0, sizeof(visited));
		if (dfs(i))
			cnt++;
	}
	return cnt;
}
int main() {
	int n, m, e;
	cin >> n >> m >> e;
	for (int i = 0; i < e; ++i) {
		int u, v;
		cin >> u >> v;
		graph[u].push_back(v);
	}
	int result = maxMatching(n);
	cout << result << endl;

	return 0;
}

第一个样例没过,第二过了,wa了两个点,求助

2023/7/26 10:23
加载中...