POJ 2594 Treasure Exploration
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 510;
int n, m;
int g[N][N];
// 匈牙利
int match[N], st[N];
int dfs(int u) {
for (int i = 1; i <= n; i++)
if (g[u][i] && !st[i]) {
st[i] = 1;
if (match[i] == -1 | dfs(match[i])) {
match[i] = u;
return 1;
}
}
return 0;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("POJ2594.in", "r", stdin);
#endif
while (scanf("%d%d", &n, &m) && (n + m)) {
memset(g, 0, sizeof g);
while (m--) {
int x, y;
scanf("%d%d", &x, &y);
g[x][y] = 1;
}
// Floyd传递闭包
for (int k = 1; k <= n; ++k)
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
g[i][j] |= g[i][k] & g[k][j];
int res = 0;
memset(match, -1, sizeof match);
for (int i = 1; i <= n; i++) {
memset(st, 0, sizeof st);
if (dfs(i)) res++;
}
printf("%d\n", n - res);
}
return 0;
}
分类:
二分图
, 二分图_最小路径重复点覆盖
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
2021-08-02 P1364 医院设置 题解
2021-08-02 P5076 【深基16.例7】普通二叉树(简化版)题解
2021-08-02 二叉树的三种遍历方式
2021-08-02 P1030 [NOIP2001 普及组] 求先序排列题解
2021-08-02 P1827 [USACO3.4]美国血统 American Heritage 题解
2018-08-02 mysql备份与还原
2017-08-02 PostgreSQL9.6.3的REDIS测试