📄 maxmatch.cpp
字号:
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 128;
class Graph {
private:
bool map[N][N], check[N];
int n, match[N];
bool dfs(int);
public:
int maxMatch();
};
bool Graph::dfs(int p) {
for(int i = 0; i < n; i++) {
if(!check[i] && map[p][i]) {
check[i] = true;
int t = match[i];
match[i] = p;
if(t == -1 || dfs(t)) return true;
match[i] = t;
}
}
return false;
}
int Graph::maxMatch() {
memset(match, -1, sizeof(match));
int mth = 0;
for(int i = 0; i < n; i++) {
memset(check, false, sizeof(check));
if(dfs(i)) mth++;
}
return mth;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -