题目链接: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. Windows:将cmd命令行添加到右键中方法

    win10中将命令行cmd添加到右键的方法 Windows cmd 右键 win10 命令行 最近在学python,所以会用到很多库文件,但是有的库文件需要下载whl文件再通过cmd进行安装,所以每次 ...

  2. 服务器证书安装配置指南(SLB)

    一.生成证书请求  1.下载CSR生成工具 您需要使用CSR生成工具来创建证书请求.  下载AutoCSR: http://www.itrus.cn/soft/autocsr.rar  2.生成服务器 ...

  3. bash变量

    bash中的变量的种类 根据变量的生效范围等标准 本地变量:生效范围为当前shell进程:对当前shell之外的其它shell进程,包括当前shell的子shell进程均无效: 环境变量:生效范围为当 ...

  4. React-Native 之 项目实战(三)

    前言 本文有配套视频,可以酌情观看. 文中内容因各人理解不同,可能会有所偏差,欢迎朋友们联系我. 文中所有内容仅供学习交流之用,不可用于商业用途,如因此引起的相关法律法规责任,与我无关. 如文中内容对 ...

  5. Nagios邮件报警

    p.MsoNormal,li.MsoNormal,div.MsoNormal { margin: 0cm; margin-bottom: .0001pt; line-height: 150%; fon ...

  6. 《Java Performance》笔记1——性能分析基础 2

    4.内存使用率: 内存使用率的相关属性包括页面调度或页面交换.加锁.线程迁移中的让步式和抢占式上下文切换. 当应用运行所需的内存超过可用物理内存时,就会发生内存页面交换,系统在进行页面交换或使用虚拟内 ...

  7. 玩转 SSH(一):使用 Struts 搭建简单站点

    我们将使用 Struts 搭建一个简单的应用,当用户发送 HTTP 请求时,Action 类响应并设置返回信息,JSP 页面显示 Action 类中设置的信息. 首先,我们使用 Maven 的 mav ...

  8. (iOS)谈谈关于使用category的静态库(原创)

    最近在一个项目中使用了一个包含catecategory 的静态库,但是此项目在运行过程中,该静态库调用 category 增加的方法处,却报 selector not recognized 异常,会直 ...

  9. ViewPager—01引导页的制作

    布局文件 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:t ...

  10. iOS图片填充UIImageView(contentMode)

    本文主要形象的介绍一下UIView的contentMode属性: 核心代码 [self.prp_imageView setContentMode:UIViewContentModeScaleAspec ...