题目1:
分析:时隔一年重温匈牙利,感觉不再像以前那样死磕证明了。。(打ACM的证个毛明啊,会用就完了,等证明完了就退役了。。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//typedef __int128 lll;
#define print(i) cout << "debug: " << i << endl
#define close() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mem(a, b) memset(a, b, sizeof(a))
const ll mod = 1e9 + 7;
const int maxn = 1010;
const int inf = 0x3f3f3f3f;
vector<int> g[maxn];
int used[maxn], match[maxn];
bool dfs(int now)
{
for(int i = 0; i < g[now].size(); i++)
{
int ep = g[now][i];
if(!used[ep])
{
used[ep] = 1;
if(!match[ep] || dfs(match[ep]))
{
match[ep] = now;
return true;
}
}
}
return false;
}
int main()
{
int n, m, e;
cin >> n >> m >> e;
for(int i = 1; i <= e; i++)
{
int x, y; cin >> x >> y;
g[x].push_back(y);
}
ll res = 0;
for(int i = 1; i <= n; i++)
{
mem(used, 0);
if(dfs(i)) res++;
}
cout << res << endl;
}