记录编号 552615 评测结果 AAAAAAAAAA
题目名称 [网络流24题] 搭配飞行员 最终得分 100
用户昵称 GravatarEvolt 是否通过 通过
代码语言 C++ 运行时间 0.004 s
提交时间 2020-07-31 13:57:41 内存使用 4.47 MiB
显示代码纯文本
#include <cstdio>
#include <cstring>
#define RE register
#define maxn 100
using namespace std;
int head[maxn | 1],num_edge;
struct edge{
	int to,next;
	edge(){
		to = next = 0;
	}
}Edge[10001];
inline void add_edge(int from,int to){
	Edge[++ num_edge].next = head[from];
	head[from] = num_edge;
	Edge[num_edge].to = to;
	return ;
}
template <typename T> inline void read(T &s){
	s = 0;
	char c = getchar();
	while(c < '0'||c > '9')c = getchar();
	while(c >= '0'&&c <= '9')s = (s << 1) + (s << 3) + c - '0',c = getchar();
	return ;
}
template <typename T> inline void write(const T &x){
	if(x > 9)write(x / 10);
	putchar(x % 10 + '0');
	return ;
}
int n,n1;
int match[maxn | 1];
bool vis[maxn | 1];
inline bool find(const int &x){
	for(int i = head[x];i;i = Edge[i].next){
		int v = Edge[i].to;
		if(vis[v])continue ;
		vis[v] = true;
		if(!match[v] || find(match[v])){
			match[v] = x;
			return true;
		}
	}
	return false;
}
inline void matched(void){
	int cnt = 0;
	memset(match , 0 , sizeof(match));
	for(int i = 1;i <= n1;++ i){
		memset(vis , false , sizeof(vis));
		if(find(i))++ cnt;
	}
	write(cnt);
	return ;
}
int main(){
	freopen("flyer.in","r",stdin);
	freopen("flyer.out","w",stdout);
	read(n);
	read(n1);
	int u,v;
	while(scanf("%d%d",&u,&v) != EOF){
		add_edge(u , v);
	}
	matched();
	fclose(stdin);
	fclose(stdout);
	return 0;
}