Pagini recente » Cod sursa (job #549859) | Cod sursa (job #2056163) | Cod sursa (job #2133930) | Cod sursa (job #1559014) | Cod sursa (job #2172419)
#include <bits/stdc++.h>
using namespace std;
const int nmax = 2e4 + 10;
int n, m, e, cnt;
int _pair[nmax];
bool used[nmax];
vector < int > g[nmax];
bool pair_up(int node) {
used[node] = 1;
for (auto &it: g[node])
if (!_pair[it]) {
_pair[node] = it; _pair[it] = node;
return 1;
}
for (auto &it: g[node])
if (!used[_pair[it]] && pair_up(_pair[it])) {
_pair[node] = it; _pair[it] = node;
return 1;
}
return 0;
}
void max_matching() {
bool ok = 1;
while (ok) {
ok = 0; memset(used, 0, sizeof(used));
for (int i = 1; i <= n; ++i)
if (!_pair[i]) ok |= pair_up(i);
}
}
int main()
{
freopen("cuplaj.in","r",stdin);
freopen("cuplaj.out","w",stdout);
ios_base :: sync_with_stdio(false);
cin >> n >> m >> e;
for (int i = 1; i <= e; ++i) {
int x, y;
cin >> x >> y; y += n;
g[x].push_back(y);
g[y].push_back(x);
}
max_matching();
for (int i = 1; i <= n; ++i)
if (_pair[i]) cnt++;
cout << cnt << '\n';
for (int i = 1; i <= n; ++i)
if (_pair[i])
cout << i << ' ' << _pair[i] - n << '\n';
return 0;
}