Pagini recente » Cod sursa (job #3175792) | Cod sursa (job #2482292) | Cod sursa (job #1805824) | Cod sursa (job #1950318) | Cod sursa (job #294570)
Cod sursa(job #294570)
#include<stdio.h>
#define N 8200
void read(),solve(),pune(),cuplaj();
struct nod{ int inf; nod *next;};
nod *vec_out[N],*paux;
int n,m,i,a,b,sol,j,ci[N],cd[N],viz[N],creste(int st),gata;
int main()
{ read();
solve();
return 0;
}
void read()
{ freopen("felinare.in","r",stdin);
freopen("felinare.out","w",stdout);
scanf("%d%d",&n,&m);
for(i=1;i<=m;i++){ scanf("%d%d",&a,&b); pune();}
}
void pune()
{ paux=new nod;
paux->inf=b; paux->next=vec_out[a]; vec_out[a]=paux;
}
void solve()
{ cuplaj();
}
void cuplaj()
{
gata=0;
while(!gata)
{
gata=1;
for(i=1;i<=n;i++) viz[i]=0;
for(i=1;i<=n;i++)
if(!cd[i]&&creste(i)){ gata=0; sol++;}
}
printf("%d\n",2*n-sol);
}
int creste(int st)
{
if(viz[st]) return 0;
viz[st]=1;
for(paux=vec_out[st];paux;paux=paux->next)
if(!ci[paux->inf]){ ci[paux->inf]=st; cd[st]=paux->inf; return 1;}
for(paux=vec_out[st];paux;paux=paux->next)
if(creste(ci[paux->inf])){ ci[paux->inf]=st; cd[st]=paux->inf; return 1;}
return 0;
}