Pagini recente » Cod sursa (job #892212) | Cod sursa (job #2487164) | Cod sursa (job #306364) | Cod sursa (job #1258440) | Cod sursa (job #1557508)
#include <cstdio>
#include <vector>
#define nmax 10005
#include <cstring>
using namespace std;
int N,M,E,C = 0;
vector <int> G[nmax];
int u[nmax],l[nmax],r[nmax];
bool pairup(int x){
for(vector <int> :: iterator it = G[x].begin();it != G[x].end();++it)
if(r[*it] == 0){
l[x] = *it;
r[*it] = x;
return true;
}
for(vector <int> :: iterator it = G[x].begin();it != G[x].end();++it)
if(pairup(r[*it])){
l[x] = *it;
r[*it] = x;
return true;
}
return false;
}
int main()
{
freopen("cuplaj.in","r",stdin);
freopen("cuplaj.out","w",stdout);
scanf("%d %d %d ",&N,&M,&E);
int x,y;
while(E--){
scanf("%d %d ",&x,&y);
G[x].push_back(y);
}
bool ok = true;
do{
ok = false;
memset(u,0,sizeof(u));
for(x = 1;x <= N;++x)
if(l[x] == 0 )ok |= pairup(x);
}while(ok == true);
for(x = 1;x <= N;++x)C += (l[x] > 0);
printf("%d\n",C);
for(x = 1;x <= N;++x)if(l[x])printf("%d %d\n",x,l[x]);
return 0;
}