比赛 202110省实验桐柏一中普及组联赛 评测结果 AWWWAAWWAW
题目名称 分配同桌 最终得分 40
用户昵称 PYD1 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2021-10-18 19:01:59
显示代码纯文本
#define MAXN 10000
#define MAXM 10000000

#include <cstdio>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

using namespace std;

inline int read(){
	int t = 0,flag = 1;
	register char c = getchar();
	while (c < 48 || c > 57) {if (c == '-') flag = -1;if (c == EOF) return -1;c = getchar();}
	while (c >= 48 && c <= 57) t = (t << 1) + (t << 3) + (c ^ 48),c = getchar();
	return flag * t;
}

struct edge{
	int u,v,next;
}e[(MAXM << 1) + 1];

int a,b,n,nn,m,u,v,ans,etot,head[(MAXN << 1) + 1],match[(MAXN << 1) + 1];
bool vis[(MAXN << 1) + 1];

void addedge(int u,int v){
	e[++etot].u = u,e[etot].v = v,e[etot].next = head[u],head[u] = etot;
}

int path(int now){
	for (int i = head[now];i;i = e[i].next){
		if (vis[e[i].v]) continue;
		vis[e[i].v] = 1;
		if (match[e[i].v] == -1 || path(match[e[i].v])){
			match[now] = e[i].v,match[e[i].v] = now;
			return 1;
		}
	}
	return 0;
}

void solve(){
	memset(match,-1,sizeof(match));
	for (int i = 1;i <= a;i++){
		memset(vis,0,sizeof(vis)),vis[i] = 1;
		if (match[i] == -1) ans += path(i);
	}
}

int main(){
	freopen("tongzhuo.in","r",stdin);
	freopen("tongzhuo.out","w",stdout);
	n = read(),nn = read(),a = n - nn,b = nn;
	while ((u = read()) != -1){
		v = read();
		addedge(u,v),addedge(v,u);
	}
	solve();
	printf("%d\n",ans);
	return 0;
}