源代码:
#include<bits/stdc++.h>
using namespace std;
#define N 2001
struct E{int v,n;E(){}}e[50001];int h[N],$;
inline void add(const int u,const int v)
{
e[++$].v=v;e[$].n=h[u];h[u]=$;
e[++$].v=u;e[$].n=h[v];h[v]=$;
}
int mc[N];
bool dfs(const int p)
{
for(int&i=h[p];i;i=e[i].n)
if(!mc[e[i].v]||dfs(mc[e[i].v])){mc[e[i].v]=p;mc[p]=e[i].v;i=e[i].n;return true;}
return false;
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);
//freopen(".in","r",stdin);
int n,m,u,v;cin>>n>>m;
while(m --> 0){cin>>u>>v;add(u,v);}
int s=0;
for(int i=1;i<=n;++i)s+=(!mc[i]&&dfs(i));
cout<<s;
return 0;
}
本地编译:失败

洛谷编译:通过