求助!WA了
查看原帖
求助!WA了
800884
Weekoder楼主2023/11/30 13:15

请各位大佬帮我看一下orz

#include <bits/stdc++.h>
using namespace std;

const int kMaxN = 5e4 + 1;

int n, m, E, e[510][510], match[kMaxN], ans;
bool book[kMaxN];

bool dfs(int u) {
	for (int i = 1; i <= m; i++) {
		if (e[u][i] && !book[i]) {
			book[i] = 1;
			if (!match[i] || dfs(match[i])) {
				match[i] = u;
				match[u] = i;
				return 1;
			}
		}
	} 
	return 0;
}

int main() {
	cin >> n >> m >> E;
	for (int i = 1; i <= E; i++) {
		int u, v;
		cin >> u >> v;
		e[u][v] = 1;
		e[v][u] = 1;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) book[i] = 0;
		if (dfs(i)) ans++;
	}
	cout << ans;
	return 0;
}
2023/11/30 13:15
加载中...