Pagini recente » Cod sursa (job #2587811) | Cod sursa (job #2307196) | Cod sursa (job #589585) | Cod sursa (job #1811043) | Cod sursa (job #589638)
Cod sursa(job #589638)
#include<stdio.h>
#define N 10005
int s[N],d[N],n,v[N],k;
struct muchie
{
int info;
muchie *next;
}*c[N],*q;
int df(int x)
{
muchie *q;
if (v[x]==1)
return 0;
v[x]=1;
q=c[x];
while (q)
{
if (d[q->info]==0)
{
s[x]=q->info;
d[q->info]=x;
return 1;
}
q=q->next;
}
q=c[x];
while (q)
{
if (df(d[q->info])==1)
{
s[x]=q->info;
d[q->info]=x;
return 1;
}
q=q->next;
}
return 0;
}
void cupleaza ()
{
int ok=0;
int i;
/*while (ok==0)
{*/
ok=1;
for (i=1;i<=n;i++)
v[i]=0;
for (i=1;i<=n;i++)
if (s[i]==0)
if (df (i)==1)
{
ok=0;
k++;
}
// }
}
int main()
{
int m,e;
freopen ("cuplaj.in","r",stdin);
freopen ("cuplaj.out","w",stdout);
scanf("%i%i%i",&n,&m,&e);
int i;
for (i=0;i<e;i++)
{
int x,y;
scanf("%i%i",&x,&y);
q=new muchie;
q->info=y;
q->next=c[x];
c[x]=q;
}
cupleaza();
printf("%i\n",k);
for (i=1;i<=N;i++)
if (s[i]!=0)
printf("%i %i\n",i,s[i]);
return 0;
}