hdu1151 Air Raid 二分匹配
题目链接: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 二分匹配的更多相关文章
- poj 1422 Air Raid (二分匹配)
Air Raid Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6520 Accepted: 3877 Descript ...
- hdu 1151 Air Raid - 二分匹配
Consider a town where all the streets are one-way and each street leads from one intersection to ano ...
- HDU1151 Air Raid —— 最小路径覆盖
题目链接:https://vjudge.net/problem/HDU-1151 Air Raid Time Limit: 2000/1000 MS (Java/Others) Memory L ...
- Hdu1151 Air Raid(最小覆盖路径)
Air Raid Problem Description Consider a town where all the streets are one-way and each street leads ...
- hdu1151 Air Raid
http://acm.hdu.edu.cn/showproblem.php?pid=1151 增广路的变种2:DAG图的最小路径覆盖=定点数-最大匹配数 #include<iostream> ...
- hdu1151 Air Raid,DAG图的最小路径覆盖
点击打开链接 有向无环图的最小路径覆盖 = 顶点数- 最大匹配 #include <queue> #include <cstdio> #include <cstring& ...
- hdu1151 Air Raid 基础匈牙利
#include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> ...
- hdu 1151 Air Raid DAG最小边覆盖 最大二分匹配
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1151 题目大意: 城镇之间互相有边,但都是单向的,并且不会构成环,现在派伞兵降落去遍历城镇,问最少最少 ...
- HDU1151:Air Raid(最小边覆盖)
Air Raid Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
随机推荐
- javaEE与JSP基础
JSP基础 1. jsp的作用: * Servlet: > 缺点:不适合设置html响应体,需要大量的response.getWriter().print("<html ...
- require include 一个隐藏的用法:作用域。
最近在研究php底层框架,奇怪的一点.控制器里为什么要把从model里获取的数据 需要$this->assign('items', $items); 这种形式模板文件里才可以调用到这个变量.控制 ...
- css3动画图片波纹效果
这里的图片很有特点,下面有演示图片样式 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &quo ...
- taobao-pamirs-proxycache开源缓存代理框架实现原理剖析
写在前面 taobao-pamirs-proxycache 是一款开源缓存代理框架, 它将 缓存代码 与 业务代码 解耦.让开发专注coding业务, 缓存通过xml配置即可实现.本文先从此工具如何使 ...
- jQuery购物车
效果图 HTML代码:(非表格方式) <div class="nav2"> <input type="checkbox" class=&quo ...
- 手机自动化测试:appium源码分析之bootstrap十一
手机自动化测试:appium源码分析之bootstrap十一 poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣 ...
- Eclipse插件ObjectAid(UML画图工具)
原链接:https://my.oschina.net/keyven/blog/856594 最近想找一个Eclipse上的插件,可以方便的把java代码转换为UML图,但是由于我用的是Eclipse ...
- Redis基础学习(五)—Redis的主从复制
一.概述 Redis的主从复制策略是通过其持久化的rdb文件来实现的,其过程是先dump出rdb文件,将rdb文件全量传输给slave,然后再将dump后的操作实时同步到slave中.让从服务 ...
- 基于MVC和Bootstrap的权限框架解决方案 二.添加增删改查按钮
上一期我们已经搭建了框架并且加入了列表的显示, 本期我们来加入增删改查按钮 整体效果如下 HTML部分,在HTML中找到中意的按钮按查看元素,复制HTML代码放入工程中 <a class=&qu ...
- nginx学习笔记——http module分析
源码:nginx 1.12.0 nginx由于其高性能.扩充性好等特点在迅速走红,越来越多的公司采用nginx作web服务器.负载均衡.waf等 工作,一些基于nginx ...