Pagini recente » Cod sursa (job #2832920) | Cod sursa (job #2056161) | Cod sursa (job #2210728) | Cod sursa (job #2274490) | Cod sursa (job #1973987)
#include <bits/stdc++.h>
using namespace std;
const int Nmax = 26013;
int Left[Nmax], Right[Nmax], L, R, E;
vector<vector<int> > G;
bitset<Nmax> used;
bool match(int k) {
if(used[k])
return false;
used[k] = true;
for(auto it : G[k])
if(Left[it] == 0) {
Left[it] = k;
Right[k] = it;
return true;
}
for(auto it : G[k])
if(match(Left[it])) {
Right[k] = it;
Left[it] = k;
return true;
}
return false;
}
int main()
{
freopen("cuplaj.in", "r", stdin);
freopen("cuplaj.out", "w", stdout);
ios::sync_with_stdio(false);
cin >> L >> R >> E;
G.resize(L + R + 1);
for(int i = 1; i <= E; ++i) {
int a,b;
cin >> a >> b;
G[a].push_back(L + b);
G[L + b].push_back(a);
}
int cuplaj = 0;
bool updated = true;
while(updated) {
updated = false;
used = 0;
for(int i = 1; i <= L; ++i)
if(!Right[i] && match(i)) {
updated = true;
cuplaj += 1;
}
}
cout << cuplaj << "\n";
for(int i = 1; i <= L; ++i)
if(Right[i])
cout << i << " " << Right[i] - L << "\n";
return 0;
}