Pagini recente » Cod sursa (job #2059217) | Cod sursa (job #1235970) | Cod sursa (job #2389433) | Cod sursa (job #3224809) | Cod sursa (job #1744028)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct list
{
int x;
list * next;
};
list * g[10009],* p;
int n,m,e,i,j,k,mt[10009];
char u[10009];
bool ok;
void add(list ** l,int v)
{
p=(list *) malloc(sizeof(list));
p->next=*l;
p->x=v;
*l=p;
}
bool dfs(int v)
{
if (u[v]) return false;
u[v]=1;
for (list * p = g[v]; p ; p=p->next)
if (! mt[p->x] || dfs(mt[p->x]))
{
mt[p->x]=v;
return true;
}
return false;
}
int main()
{
FILE * in,*out;
in=freopen("cuplaj.in","r",stdin);
out=freopen("cuplaj.out","w",stdout);
scanf("%d%d%d",&n,&m,&e);
while (e--)
{
scanf("%d%d",&i,&j);
add(&g[i],j);
}
for (i=1;i<=n;++i)
{
memset(u,0,sizeof(u));
ok=dfs(i);
}
for (i=1;i<=m;++i)
if (mt[i])
k++;
printf("%d\n",k);
for (i=1;i<=m;++i)
if (mt[i])
printf("%d %d\n",mt[i],i);
fclose(in);
fclose(out);
return 0;
}