传送门

引子:

有一个问题,是对于一个图上的所有点,用不相交的路径把他们覆盖,使得每个点有且仅属于一条路径,且这个路径数量尽量小。

对于这个问题可以把直接有边相连的两点 x —> y,建一个二分图 x' —> y,最后 节点数 - 最大匹配数 即为最终答案。

这才是题解:

但是这个题目不同,此题问的是用一些路径把所有点覆盖,并没有说每个点有且仅属于一条路径,所以需要求这个图的传递闭包。

把可达的两点建立二分图。最后 节点数 - 最大匹配数 即为最终答案。

可以看看这篇blog

——代码

 #include <cstdio>
#include <cstring>
#define M(x, a) memset(a, x, sizeof(a)); using namespace std; const int MAXN = ;
int n, m, ans, cnt;
int belong[MAXN];
bool a[MAXN][MAXN], vis[MAXN]; inline bool find(int i)
{
int j;
for(j = ; j <= n; j++)
if(!vis[j] && a[i][j])
{
vis[j] = ;
if(!belong[j] || find(belong[j]))
{
belong[j] = i;
return ;
}
}
return ;
} int main()
{
int i, j, k, x, y;
while(scanf("%d %d", &n, &m) && n + m)
{
ans = ;
M(, a);
M(, belong);
for(i = ; i <= m; i++)
{
scanf("%d %d", &x, &y);
a[x][y] = ;
}
for(k = ; k <= n; k++)
for(i = ; i <= n; i++)
for(j = ; j <= n; j++)
a[i][j] = a[i][j] || (a[i][k] && a[k][j]);
for(i = ; i <= n; i++)
{
memset(vis, , sizeof(vis));
if(find(i)) ans++;
}
printf("%d\n", n - ans);
}
}

[POJ2594] Treasure Exploration(最小路径覆盖-传递闭包 + 匈牙利算法)的更多相关文章

  1. POJ2594 Treasure Exploratio —— 最小路径覆盖 + 传递闭包

    题目链接:https://vjudge.net/problem/POJ-2594 Treasure Exploration Time Limit: 6000MS   Memory Limit: 655 ...

  2. poj 2594 Treasure Exploration(最小路径覆盖+闭包传递)

    http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total ...

  3. cogs 728. [网络流24题] 最小路径覆盖问题 匈牙利算法

    728. [网络流24题] 最小路径覆盖问题 ★★★☆   输入文件:path3.in   输出文件:path3.out   评测插件时间限制:1 s   内存限制:128 MB 算法实现题8-3 最 ...

  4. POJ-2594 Treasure Exploration floyd传递闭包+最小路径覆盖,nice!

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 8130   Accepted: 3 ...

  5. POJ-2594 Treasure Exploration,floyd+最小路径覆盖!

                                                 Treasure Exploration 复见此题,时隔久远,已忘,悲矣! 题意:用最少的机器人沿单向边走完( ...

  6. POJ2594:Treasure Exploration(Floyd + 最小路径覆盖)

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 9794   Accepted: 3 ...

  7. POJ 2594 —— Treasure Exploration——————【最小路径覆盖、可重点、floyd传递闭包】

    Treasure Exploration Time Limit:6000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64 ...

  8. POJ2594 Treasure Exploration【DAG有向图可相交的最小路径覆盖】

    题目链接:http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K T ...

  9. POJ2594 Treasure Exploration(最小路径覆盖)

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 8550   Accepted: 3 ...

随机推荐

  1. KMS算法

    解题:http://hihocoder.com/problemset/problem/1015 KMP算法是一种改进的字符串匹配算法,由D.E.Knuth,J.H.Morris和V.R.Pratt同时 ...

  2. Vue checkbox默认值改变

    <label><input  v-bind:true-value="1" v-bind:false-value="0" type=" ...

  3. 释放资源的一般范式——更锋利的C#代码小记

    public class Photo : IDisposable { //在Finalize函数中调用内部的Dispose方法 ~Photo() { //被自动回收时仅释放托管资源,不释放非托管资源 ...

  4. Android设计模式——MVP

    一.什么是MVP MVP:全称 Model-View-Presenter. MVP框架由3部分组成:View层负责显示,Presenter层负责逻辑处理,Model层提供数据. View:负责绘制UI ...

  5. ASP.NET MVC IIS7 403.14-Forbidden

    问题描述 IIS 7上发布ASP.NET MVC程序报错:403.14-Forbidden Web 服务器被配置为不列出此目录的内容 折腾了半天,提示里面的解决方法是: 如果不希望启用目录浏览,请确保 ...

  6. 【HEVC简介】SAO-Sample Adaptive Offset, 样本自适应偏移量

    paper: Sample Adaptive Offset for HEVC <HEVC标准介绍.HEVC帧间预测论文笔记>系列博客,目录见:http://www.cnblogs.com/ ...

  7. android应用流量信息提取

    Linux 系统下所有的信息都是以文件的形式存在的,所以应用程序的流量信息也会被保存在操作系统的文件中.Android 2.2 版本以前的系统的流量信息都存放在 proc/net/dev(或者 pro ...

  8. 小知识~VS2012的xamarin加载失败解决

    1 由于Nuget版本过低导致的,工具->扩展和更新->在线更新->对nuget程序包程序器进行升级即可 错误代码: 错误    4    错误: 缺少来自类“NuGet.Visua ...

  9. About App Sandbox

    沙盒是在受限的安全环境中运行应用程序的一种做法,这种做法是要限制授予应用程序的代码访问权限. 沙盒技术提供对资源的严格控制,沙盒通过限制对内存.系统文件和设置的访问,沙盒可以让企业可通过执行潜在恶意代 ...

  10. 看Spring Data如何简化数据操作

    Spring Data 概述 Spring Data 用于简化数据库访问,支持NoSQL 和 关系数据存储,其主要目标是使数据库的访问变得方便快捷. SpringData 项目所支持 NoSQL 存储 ...