poj 2594(最小路径覆盖问题)
来源:互联网 发布:女用自慰器 知乎 编辑:程序博客网 时间:2024/04/27 14:52
题目链接:点击打开链接
题目分析:如果没有相交边的情况,那么问题就简单了; 最小路径覆盖=最小路径覆盖=|G|-最大匹配数;
有相交边应该怎么做呢,floyd闭包传递就可以了; 可以参考博客 点击打开链接
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int n, m, maze[510][510], linker[510];bool used[510];void Floyd(){ for(int k = 1; k <= n; ++k) for(int i = 1; i <= n; ++i) if(maze[i][k]){ for(int j = 1; j <= n; ++j) if(maze[k][j]) maze[i][j] = 1; }}bool dfs(int u){ for(int v = 1; v <= n; ++v){ if(maze[u][v] && !used[v]){ used[v] = true; if(linker[v] == -1 || dfs(linker[v])){ linker[v] = u; return true; } } } return false;}int hungary(){ int res = 0; memset(linker, -1, sizeof(linker)); for(int i = 1; i <= n; ++i){ memset(used, false, sizeof(used)); if(dfs(i)) ++res; } return res;}int main(){ while(~scanf("%d%d", &n, &m) && (n||m)){ memset(maze, 0, sizeof(maze)); int u, v; for(int i = 0; i < m; ++i){ scanf("%d%d", &u, &v); maze[u][v] = 1; } Floyd(); // 因为可以走同一个节点, 传递闭包处理节点; int ans = hungary(); printf("%d\n", n-ans); }}
0 0
- poj 2594(最小路径覆盖问题)
- poj 2594(最小路径覆盖)
- 最小路径覆盖问题(最小路径覆盖)
- POJ 2594 Treasure Exploration(最小路径覆盖变形)
- POJ 题目2594 Treasure Exploration(最小路径覆盖)
- POJ 2594 Treasure Exploration(最小路径覆盖-hungary+Floyd)
- POJ 2594 Treasure Exploration(最小路径覆盖)
- POJ-2594-Treasure Exploration(可重点最小路径覆盖)
- POJ-2594 Treasure Exploration(最小路径覆盖)
- poj/pku 2594 (最小路径覆盖)
- 【最小路径覆盖+注意】POJ 2594
- poj 2594-flody + 最小路径覆盖
- poj 2594 floyd+最小路径覆盖
- POJ 2594 最小路径覆盖 二分匹配
- POJ 2594 Treasure Exploration 最小路径覆盖
- POJ 2594 (最小路径覆盖+可重点)
- POJ 2594 二分图最小路径覆盖
- poj(3216)最小路径覆盖
- SPOJ DISUBSTR(后缀数组)
- 数据挖掘算法与现实生活中的应用案例
- 浅谈Handler,Loop,MessageQueue,Thread的小秘密
- 记使用linux命令行编译c语言步骤
- JavaScript之元素在屏幕从左到右移动的的示例
- poj 2594(最小路径覆盖问题)
- codeforces#327-C.Median Smoothing-规律题
- How to create a bootable USB stick on Windows
- 基于Unity行为树设计与实现的尝试
- POJ 3050 Hopscotch
- 第六周数据结构实践——后缀表达式(栈)【项目5 - 后缀表达式】
- HTTP 请求方式: GET和POST的比较
- DownFile
- XVWA黑客靶场发布