自己整理模板
#include <bits/stdc++.h>
#define inf 1e10
using namespace std;
typedef long long ll;
const int maxn=1e5+20;
int head[maxn];
int match[maxn];
int step,ans=0;
bool vis[maxn];
struct node
{
int from,to,next;
}edge[maxn];
void add(int from,int to)
{
edge[step].to=to;
edge[step].next=head[from];
head[from]=step;
step++;
}
bool dfs(int u)
{
for(int i=head[u];i!=-1;i=edge[i].next)
{
int y=edge[i].to;
if(vis[y]) continue;
vis[y]=true;
if(!match[y]||dfs(match[y]))
{
match[u]=y;
match[y]=u;
return true;
}
}
return false;
}
int main()
{
int n;
cin>>n;
int m;
cin>>m;
memset(head,-1,sizeof(head));
step=0;
for(int i=0;i<m;i++){
int x,y;
cin>>x>>y;
add(x,y);
add(y,x);
}
for(int i=1;i<=n;i++)
{
if(match[i]) continue;
memset(vis,false,sizeof(vis));
if(dfs(i)) ans++;
}
cout<<ans<<endl;
return 0;
}