惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

云风的 BLOG
云风的 BLOG
TaoSecurity Blog
TaoSecurity Blog
V
Visual Studio Blog
The GitHub Blog
The GitHub Blog
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
The Register - Security
The Register - Security
月光博客
月光博客
M
MIT News - Artificial intelligence
B
Blog RSS Feed
博客园 - 叶小钗
Last Week in AI
Last Week in AI
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
The Blog of Author Tim Ferriss
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Azure Blog
Microsoft Azure Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
Check Point Blog
Attack and Defense Labs
Attack and Defense Labs
The Cloudflare Blog
Cloudbric
Cloudbric
O
OpenAI News
Security Archives - TechRepublic
Security Archives - TechRepublic
Help Net Security
Help Net Security
Google DeepMind News
Google DeepMind News
Stack Overflow Blog
Stack Overflow Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
V2EX
大猫的无限游戏
大猫的无限游戏
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V2EX - 技术
V2EX - 技术
Google Online Security Blog
Google Online Security Blog
博客园 - Franky
雷峰网
雷峰网
J
Java Code Geeks
L
LINUX DO - 最新话题
T
Tenable Blog
爱范儿
爱范儿
Engineering at Meta
Engineering at Meta
T
Tailwind CSS Blog
Spread Privacy
Spread Privacy
H
Heimdal Security Blog
S
Schneier on Security
量子位
N
Netflix TechBlog - Medium
G
Google Developers Blog
T
The Exploit Database - CXSecurity.com
Cyberwarzone
Cyberwarzone
F
Full Disclosure
S
Securelist

Ayx 博客

PaperMC 服务器允许刷线机/无头活塞等配置 如何从 YouTube 搬运视频?如何做一个合格的 YouTube 搬运工?我搬运视频的方法与原则 此博客的所有镜像 免费获取在 Microsoft Store 中收费 ¥7.00 的 HEVC 视频扩展 CLI Post Test moefox.tech 已于 7 月 25 日过期,本站域名已更换为 imayx.top 关于 链接 LG V50 ThinQ 韩版 LGU+ 从解锁 BootLoader 到破解 VoLTE / NSA 5G、从刷入第三方 Recovery 到硬格、从混刷到黑砖全教程 Python 3 入门学习笔记 新年快乐 & 本站的改版 在 Hugo 主题 Stack 中轻松配置 Waline 评论系统 出现 error: ld returned 1 exit status 的五种原因以及解决方法 MySSL 安全签章 题解 P1603 斯诺登的密码 安装 Hugo 主题 Stack 时你可能会遇到的问题 独角兽搜索 Hello Hugo 题解 UPC-1488 客户调查(client) 题解 P5707 【深基2.例12】上学迟到 题解 P2669 [NOIP2015 普及组] 金币 题解 P5719 【深基4.例3】分类平均 分享一下我的博客园在用的修改版 Wider Gao 博客园主题 使用 Node.js(安装Hexo)时出现了 rollbackFailedOptional 错误的解决方法 题解 YBT 1000:入门测试题目 题解 P1650 田忌赛马 OJ术语的解释: AC、WA、TLE、OLE、MLE、RE、PE、CE、UKE 都是些啥? 归档 搜索 友链
题解 HDU2063 过山车
2020-12-30 · via Ayx 博客

题面链接

HDU 2063

Vjudge

题意概述

求一个二分图最大匹配的边数

题目标签

匈牙利算法模板题

参考代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <bits/stdc++.h>
using namespace std;
#define maxn 1000 + 10
int n, m, k, head[maxn], link[maxn], cnt, tot;
bool vis[maxn];
struct Edge
{
	int to, nxt;
}edge[maxn];
void add(int u, int v)
{
	edge[cnt].to = v;
	edge[cnt].nxt = head[u];
	head[u] = cnt;
	cnt++;
}
bool dfs(int u) //深搜判断对于点集v2中的一个点u是否能与点集v1中的一个点v匹配
{
	for(int i = head[u]; i != -1; i = edge[i].nxt){ //枚举能匹配的点
		int v = edge[i].to; //v为能与u匹配的点编号
		if(vis[v]) continue; //利用一个vis判断当前点是否尝试匹配过,如果已经匹配过就跳过以防死循环
		vis[v] = true;
		if(link[v] == -1 || dfs(link[v])){ //如果v可以腾出位置(即没有与v2中的任何一个点匹配或v2中还存在没有匹配过的点可以与之匹配)
			link[v] = u; //u与v成功匹配
			return true;
		}
	}
	return false;
}
int getcp(int n){
	int ans = 0;
	memset(link, -1, sizeof(link));
	for(int i = 1; i <= n; i++){ //遍历每个点集v2中的点
		memset(vis, false, sizeof(vis));
		if(dfs(i)) ans++;
	}
	return ans;
}
int main(){
	while(scanf("%d", &k) != EOF){
		if(!k) break;
		scanf("%d%d", &m, &n);
		memset(head, -1, sizeof(head));
		cnt = 0;
		for(int i = 1; i <= k; i++){
			int u, v;
			scanf("%d%d", &u, &v);
			v += m; //把点集v1中的点的编号调整到点集v2后面
			add(u, v);
		}
		printf("%d\n", getcp(m));
	}
	return 0;
}

参考博文

想理解匈牙利算法的概念,推荐阅读趣写算法系列之–匈牙利算法(推荐在教练的陪同下阅读)

评论区有朋友通俗易懂地概括了它的思想:先到先得 能让就让

hdu 2063 过山车 (匈牙利算法模板题) – 111qqz的小窝


编辑记录

2021-08-05 13:37:00