标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 19208 Accepted Submission(s): 8393
代码:
#include <iostream>
#include <vector>
#include <cstring>
#include <cstdio>
using namespace std;
int vis[505],link[505];
vector<int>mp[505];
int n,m;
int dfs(int x)
{
for(int i=0;i<mp[x].size();i++)
{ int v=mp[x][i];
if(!vis[v])
{
vis[v]=1;
if(link[v]==-1||dfs(link[v]))
{ link[v]=x;
return 1;}
}
}
return 0;
}
int main()
{ int k,a,b;
while(cin>>k)
{ if(k==0)
break;
cin>>n>>m;
for(int i=1;i<=n;i++)
if(mp[i].size())
mp[i].clear();
while(k--)
{
scanf("%d%d",&a,&b);
mp[a].push_back(b);
}
memset(link,-1,sizeof(link));
int res=0;
for(int i=1;i<=n;i++)
{ memset(vis,0,sizeof(vis));
if(dfs(i))
res++;
}
cout<<res<<endl;
}
}
标签:
原文地址:http://www.cnblogs.com/llsq/p/5914049.html