过山车 HDU - 2063
作者:互联网
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
const int N=1e5;//点数的最大值
int e[N],ne[N],idx,h[N];
int K,M,N;
void init() {
idx=0;
memset(h,-1,sizeof(h));
}
void addedge(int a,int b) {
e[idx]=b;
ne[idx]=h[a];
h[a]=idx++;
}
int match[N];
bool used[N];
int uN;
bool dfs(int u) {
for(int i=h[u]; i!=-1; i=ne[i]) {
int v=e[i];
if(!used[v]) {
used[v]=true;
if(match[v]==-1||dfs(match[v])) {
match[v]=u;
return true;
}
}
}
return false;
}
int solve() {
int res=0;
memset(match,-1,sizeof(match));
for(int u=0; u<M; u++) {
memset(used,false,sizeof(used));
if(dfs(u))
res++;
}
return res;
}
int main() {
int i,ans;
int u,v;
while(~scanf("%d",&K)) {
if(K==0)
break;
scanf("%d%d",&M,&N);
uN=M;
init();
for(i=0; i<K; ++i) {
scanf("%d%d",&u,&v);
addedge(--u,--v);
}
ans=solve();
printf("%d\n",ans);
}
return 0;
}
标签:HDU,include,idx,int,过山车,ne,used,2063,match 来源: https://www.cnblogs.com/QingyuYYYYY/p/12402379.html