Pagini recente » Cod sursa (job #1997971) | Cod sursa (job #2236665) | Cod sursa (job #2849201) | Cod sursa (job #122867) | Cod sursa (job #461288)
Cod sursa(job #461288)
#include <stdio.h>
#include <vector>
#define Nmax 10002
#define pb push_back
using namespace std;
vector< int > V[Nmax];
int L[Nmax],R[Nmax];
int use[Nmax];
int n,m,e,nr;
int cuplez(int i){
vector< int >:: iterator it;
use[i]=1;
for(it=V[i].begin(); it!=V[i].end(); ++it)
if( !R[*it] || ( !use[R[*it]] && cuplez(R[*it]) ) ){
L[i]=*it; R[*it]=i;
return 1;
}
return 0;
}
void cuplaj(){
int i,done=0;
while( !done ){
done=1;
memset(use,0,sizeof(use));
for(i=1;i<=n;++i)
if( !L[i] && cuplez(i) ){
++nr;
done=0;
}
}
}
int main(){
int i,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].pb(y);
}
cuplaj();
printf("%d\n",nr);
for(i=1;i<=n;++i)
if(L[i]) printf("%d %d\n",i,L[i]);
fclose(stdin); fclose(stdout);
return 0;
}