#include<iostream>
#include<cstring>
#define MAX 1000
using namespace std
;
int vis
[MAX
],match
[MAX
];
int head
[MAX
];
int cnt
= 0,n
;
struct node
{
int to
,next
;
}edge
[MAX
*MAX
];
void addedge(int from
,int to
)
{
edge
[cnt
] = {to
,head
[from
]};
head
[from
] = cnt
++;
}
int getit(int now
)
{
for(int i
= head
[now
];~i
;i
=edge
[i
].next
)
{
int to
= edge
[i
].to
;
if(vis
[to
]) continue;
vis
[to
] = 1;
if(match
[to
] == 0 || getit(match
[to
]))
{
match
[to
] = now
;
return 1;
}
}
return 0;
}
void getans()
{
int ans
= 0;
for(int i
= 1 ; i
<= n
; i
++ )
{
memset(vis
,0,sizeof(vis
));
if(getit(i
)) ans
++;
}
cout
<<ans
<<endl
;
}
int main()
{
int m
,a
,b
;
memset(head
,-1,sizeof(head
));
cin
>>n
>>m
;
for(int i
= 0 ; i
< m
; i
++)
{
cin
>>a
>>b
;
addedge(a
,b
);
}
getans();
return 0;
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-23500.html