标签:
Description
Input
Output
Sample Input
3 4 1 1 1 3 2 2 3 2
Sample Output
2
Hint
#include<cstdio> #include<cstring> #include<vector> #include<algorithm> #define pb push_back using namespace std; int k,n,link[505],vis[505]; vector<int>G[505]; bool dfs(int u) { for(int len=G[u].size(),i=0;i<len;i++) { int v=G[u][i]; if(!vis[v]) { vis[v]=1; if(link[v]==-1||dfs(link[v])) { link[v]=u; return 1; } } } return 0; } int match() { int ans=0; memset(link,-1,sizeof(link)); for(int i=1;i<=n;i++) { memset(vis,0,sizeof(vis)); if(dfs(i))ans++; } return ans; } int main() { scanf("%d%d",&n,&k); for(int i=0;i<=n;i++)G[i].clear(); while(k--) { int u,v; scanf("%d%d",&u,&v); G[u].pb(v); } printf("%d\n",match()); return 0; }
标签:
原文地址:http://www.cnblogs.com/homura/p/5870552.html