题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1151

求最小路径覆盖

二分图最小路径覆盖=点的个数-最大匹配。

代码:

 #include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
using namespace std;
#define maxn 125
int g[maxn][maxn];
int vis[maxn];
int cx[maxn];
int cy[maxn];
int n;
int m;
int ans;
int path(int u)
{ vis[u]=;
for(int v=;v<=n;v++)
{
if(vis[v]== && g[u][v]!=)
{
vis[v]=; if(cy[v]==- || path(cy[v]))
{
cx[u]=v;
cy[v]=u;
return ;
}
}
}
return ;
}
void MaxMatch()
{
memset(cx,-,sizeof(cx));
memset(cy,-,sizeof(cy)); for(int i=;i<=n;i++)
{
if(cx[i]==-)
{ memset(vis,,sizeof(vis));
ans+=path(i);
}
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
ans=;
scanf("%d",&n);
scanf("%d",&m);
memset(g,,sizeof(g));
int s,e;
for(int i=;i<m;i++)
{
scanf("%d%d", &s,&e);
g[s][e]=;
}
MaxMatch();
cout<<n-ans<<endl; }
return ;
}

hdu1151 Air Raid 二分匹配的更多相关文章

  1. poj 1422 Air Raid (二分匹配)

    Air Raid Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6520   Accepted: 3877 Descript ...

  2. hdu 1151 Air Raid - 二分匹配

    Consider a town where all the streets are one-way and each street leads from one intersection to ano ...

  3. HDU1151 Air Raid —— 最小路径覆盖

    题目链接:https://vjudge.net/problem/HDU-1151 Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory L ...

  4. Hdu1151 Air Raid(最小覆盖路径)

    Air Raid Problem Description Consider a town where all the streets are one-way and each street leads ...

  5. hdu1151 Air Raid

    http://acm.hdu.edu.cn/showproblem.php?pid=1151 增广路的变种2:DAG图的最小路径覆盖=定点数-最大匹配数 #include<iostream> ...

  6. hdu1151 Air Raid,DAG图的最小路径覆盖

    点击打开链接 有向无环图的最小路径覆盖 = 顶点数- 最大匹配 #include <queue> #include <cstdio> #include <cstring& ...

  7. hdu1151 Air Raid 基础匈牙利

    #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> ...

  8. hdu 1151 Air Raid DAG最小边覆盖 最大二分匹配

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1151 题目大意: 城镇之间互相有边,但都是单向的,并且不会构成环,现在派伞兵降落去遍历城镇,问最少最少 ...

  9. HDU1151:Air Raid(最小边覆盖)

    Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

随机推荐

  1. 组件之间使用Prop传递数据

    <div id="example"> <father></father> </div> <script src="h ...

  2. moment倒计时插件

    https://github.com/icambron/moment-countdown

  3. [Android]使用RecyclerView替代ListView(四:SeizeRecyclerView)

    以下内容为原创,欢迎转载,转载请注明 来自天天博客:<> [Android]使用RecyclerView替代ListView(四:SeizeRecyclerView) 在RecyclerV ...

  4. linux最常用命令

    1,cd命令   作用:切换当前目录,它的参数切换的路劲,可以是相对路劲,也可以是绝对路劲. 用法: cd /root/Docements #切换当/root/Docements,绝对路劲 cd ./ ...

  5. 一步操作配置Word环境

    我们在开始编辑Word文档的时候,会发现有些事情我们总需要预先操作一下,比如100%普通视图.显示隐藏特殊标记.显示标尺.最大化窗口.显示导航窗格啥的,每次去操作,感觉很烦,那么通过下面这个宏代码可以 ...

  6. C# Task 源代码(2)

    上篇已经讲到Task 的默认的TaskScheduler 为ThreadPoolTaskScheduler. 这时我们回到原来的task 的start方法,在代码最后,调用了 ScheduleAndS ...

  7. JSP带有属性的自定义标签

    新建HelloWelTag类 如何添加jsp-api.jar包 HelloWelTag类详细代码```package bid.zhazhapan.fims.tag;import java.io.IOE ...

  8. linux之shell编程基本语法

    Shell是用户与内核进行交互操作的一种接口,目前最流行的Shell称为bash Shell.Shell也是一门编程语言<解释型的编程语言>,即shell脚本<就是在用linux的s ...

  9. 【Scala】Scala之Traits

    一.前言 前面学习了Scala中包和导入的相关知识点,接着学习Traits(特质) 二.Traits Scala的特质与Java的接口基本相同,当遇到可以使用Java接口的情形,就可以考虑使用特质,S ...

  10. [Python Web]配置 nginx 遇到错误排查(初级)

    配置 nginx 遇到错误排查(初级) 系统版本:ubuntu 14.04,nginx 版本:nginx/1.4.6 (Ubuntu) 本文不是一步步搭建 nginx 的过程,而是我在使用 nginx ...