Pagini recente » Cod sursa (job #1220343) | Cod sursa (job #2167271) | Cod sursa (job #691476) | Cod sursa (job #422338) | Cod sursa (job #1820417)
#include <cstdio>
#include <algorithm>
using namespace std;
vector <int> v[10005];
bool used[10005];
int L[10005], R[10005];
bool match(int node){
if(used[node]){
return 0;
}
used[node] = 1;
for(auto it : v[node]){
if(R[it] == 0){
L[node] = it;
R[it] = node;
return 1;
}
}
for(auto it : v[node]){
if(match(R[it])){
L[node] = it;
R[it] = node;
return 1;
}
}
return 0;
}
int main(){
int n,m,e,i,j,x,y;
freopen("cuplaj.in", "r", stdin);
freopen("cuplaj.out", "w", stdout);
scanf("%d %d %d", &n, &m, &e);
for(i = 1;i <= e;i++){
scanf("%d %d", &x, &y);
v[x].push_back(y);
}
int ans = 0;
bool ok;
for(ok = 1;ok;){
ok = 0;
for(i = 1;i <= n;i++){
used[i] = 0;
}
for(i = 1;i <= n;i++){
if(L[i] == 0){
if(match(i)){
ok = 1;
ans++;
}
}
}
}
printf("%d\n", ans);
for(i = 1;i <= n;i++){
if(L[i]){
printf("%d %d\n", i, L[i]);
}
}
return 0;
}