Air Raid

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4591    Accepted Submission(s):
3072

Problem Description
Consider a town where all the streets are one-way and
each street leads from one intersection to another. It is also known that
starting from an intersection and walking through town's streets you can never
reach the same intersection i.e. the town's streets form no cycles.

With
these assumptions your task is to write a program that finds the minimum number
of paratroopers that can descend on the town and visit all the intersections of
this town in such a way that more than one paratrooper visits no intersection.
Each paratrooper lands at an intersection and can visit other intersections
following the town streets. There are no restrictions about the starting
intersection for each paratrooper.

 
Input
Your program should read sets of data. The first line
of the input file contains the number of the data sets. Each data set specifies
the structure of a town and has the
format:

no_of_intersections
no_of_streets
S1 E1
S2
E2
......
Sno_of_streets Eno_of_streets

The first line of each data
set contains a positive integer no_of_intersections (greater than 0 and less or
equal to 120), which is the number of intersections in the town. The second line
contains a positive integer no_of_streets, which is the number of streets in the
town. The next no_of_streets lines, one for each street in the town, are
randomly ordered and represent the town's streets. The line corresponding to
street k (k <= no_of_streets) consists of two positive integers, separated by
one blank: Sk (1 <= Sk <= no_of_intersections) - the number of the
intersection that is the start of the street, and Ek (1 <= Ek <=
no_of_intersections) - the number of the intersection that is the end of the
street. Intersections are represented by integers from 1 to
no_of_intersections.

There are no blank lines between consecutive sets of
data. Input data are correct.

 
Output
The result of the program is on standard output. For
each input data set the program prints on a single line, starting from the
beginning of the line, one integer: the minimum number of paratroopers required
to visit all the intersections in the town.
 
Sample Input
2
4
3
3 4
1 3
2 3
3
3
1 3
1 2
2 3
 
Sample Output
2
1
 

翻译一下就是:

一个城镇中有n个路口和m条单项的路径,图是无环图。

有一些伞兵可以从任意一个路口出发,要求走不相交的路径并到达所有的路口;

我们的任务就是求出最少要几个伞兵。


那么很显然就是最小路径覆盖问题了(什么你不会最小路径覆盖?)

样例:

4 3

1 3

2 3

3 4

图一(样例)

图二(转换为二分图)

然后:有向图的最小路径覆盖=V-二分图最大匹配。


代码:我依旧跑的是dinic

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<cstring>
#define yyj(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout);
#define llg long long
#define maxn 2000
llg j,k,n,m,y,z,bj[maxn],head,tail,dl[maxn],deep[maxn],ans;
bool f,ff;
using namespace std;
vector <llg> a[maxn],v[maxn],ba[maxn];
//a[i][j]表示第i个点所指向的第j个点是a[i][j],v[i][j]表示权值(流量),ba[i][j]表示a[i][j]的反xiangbian
llg dfs(llg x,llg low)
{
llg res=;llg va=;
if (x==n) {return low;}
llg w=a[x].size();
for (llg i=;i<w;i++)
if (deep[x]+==deep[a[x][i]] && v[x][i]> && (va=dfs(a[x][i],min(low,v[x][i]))))
{
v[x][i]-=va; v[a[x][i]][ba[x][i]]+=va;
return va;
}
return ;
}
void fencen()
{
memset(bj,,sizeof(bj));
tail=; head=; dl[]=; bj[]=;
do{
head++;
llg x=dl[head];
llg w=a[x].size();
for (llg i=;i<w;i++)
if (!bj[a[x][i]] && v[x][i]>)
{
tail++; dl[tail]=a[x][i];
deep[a[x][i]]=deep[x]+;
bj[a[x][i]]=;
}
}while (head!=tail);
}
void insert(llg x,llg y,llg z)
{
a[x].push_back(y); v[x].push_back(z);
a[y].push_back(x); v[y].push_back();
ba[x].push_back(a[y].size()-); ba[y].push_back(a[x].size()-);
}
int main()
{
yyj("a");
cin>>n>>m; deep[]=;
for (llg i=;i<=m;i++)
{
llg x;
cin>>x>>y;
insert(x*-,y*,); insert(x*,y*-,);
}
for (llg i=;i<=n;i++)
{
insert(,i*-,); insert(i*-,,);
insert(i*,n*+,); insert(n*+,i*,);
}
llg total=n;
n=n*+;
while ()
{
f=true; ff=false;
fencen();
if (!bj[n]) break;
ans+=dfs(,0x7fffffff);
}
cout<<total-ans<<endl;
return ;
}

再说几句:

  还记得题干中打了红色标记的地方吧!“不相交的路径”

  要是可以相交呢?那我们就要跑一遍floyed闭包传递了。

  什么你搞不清很清粗为什么要这样?(自己去看一看http://www.cnblogs.com/ka200812/archive/2011/07/31/2122641.html)
  图片来自:http://www.cppblog.com/zhangwangcz/archive/2012/03/30/155686.html

【网络流24题----03】Air Raid最小路径覆盖的更多相关文章

  1. 【网络流24题】 No.3 最小路径覆盖问题 (网络流|匈牙利算法 ->最大二分匹配)

    [题意] 给定有向图 G=(V,E).设 P 是 G 的一个简单路(顶点不相交) 的集合.如果 V 中每个顶点恰好在 P 的一条路上,则称 P 是 G 的一个路径覆盖. P 中路径可以从 V 的任何一 ...

  2. (hdu step 6.3.3)Air Raid(最小路径覆盖:求用最少边把全部的顶点都覆盖)

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

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

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

  4. (step6.3.4)hdu 1151(Air Raid——最小路径覆盖)

    题意:     一个镇里所有的路都是单向路且不会组成回路. 派一些伞兵去那个镇里,要到达所有的路口,有一些或者没有伞兵可以不去那些路口,只要其他人能完成这个任务.每个在一个路口着陆了的伞兵可以沿着街去 ...

  5. hdu 1151 Air Raid 最小路径覆盖

    题意:一个城镇有n个路口,m条路.每条路单向,且路无环.现在派遣伞兵去巡逻所有路口,伞兵只能沿着路走,且每个伞兵经过的路口不重合.求最少派遣的伞兵数量. 建图之后的就转化成邮箱无环图的最小路径覆盖问题 ...

  6. POJ 1422 Air Raid (最小路径覆盖)

    题意 给定一个有向图,在这个图上的某些点上放伞兵,可以使伞兵可以走到图上所有的点.且每个点只被一个伞兵走一次.问至少放多少伞兵. 思路 裸的最小路径覆盖. °最小路径覆盖 [路径覆盖]在一个有向图G( ...

  7. Air Raid(最小路径覆盖)

    Air Raid Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7511   Accepted: 4471 Descript ...

  8. LibreOJ #6013. 「网络流 24 题」负载平衡 最小费用最大流 供应平衡问题

    #6013. 「网络流 24 题」负载平衡 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论测试数据   题目描述 ...

  9. LibreOJ #6008. 「网络流 24 题」餐巾计划 最小费用最大流 建图

    #6008. 「网络流 24 题」餐巾计划 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论测试数据   题目描述 ...

随机推荐

  1. JQuery ajax方法及参数

    ©屋主原创,版权归 todayeeee 所有!如需转载,必须在页面明显位置给出原文链接!商业用途请 联系我!   $.ajax({ type: 'GET',    // 这是请求的方式 可以是GET方 ...

  2. Microsoft JET Database Engine (0x80004005)

    解决方法:打开我的电脑,菜单栏工具选项下去掉打钩查看卡里使用简单文件共享(推荐)这项. 找到windows/temp文件夹,对temp右键属性,安全选项里添加everyone这个用户,选择完全控制权限 ...

  3. Oracle集合运算符 交集 并集 差集

     集合运算符:UNION/UNION ALL 并集,INTERSECT 交集,MINUS 差集  一.union求并集,公共部分只有包含一次 例:求emp表ename中含’A‘或含有‘M’ SQL&g ...

  4. OpenStack集成Docker

    声明:绝对原创,欢迎转载,但请标明出处,谢谢! 最近在做openstack与Docker的集成工作,走了不少弯路,遇到不少问题,不过最终搭建成功了.现在将过程分享出来,以供参考. 一.环境介绍 1.软 ...

  5. mysql 关联条件与查询(过滤)条件

    mysql用outer join时 on 后边只是关联条件,有时可能会查出无用的记录, 需用where查询条件过滤 五欧诺个的数据. 记录一下

  6. [Ogre][地形]OgreTerrain分析以及使用

    Ogre 1.7.2中的地形教程 ○读者可以对照着Ogre1.7.2中的terrain.h源码进行阅读加深理解,蓝色部分均为源码 ○去除了一些具体场景比如添加mesh,设置setAmbientLigh ...

  7. 这题实在不知道起啥名好了 分类: sdutOJ 2015-06-22 17:17 19人阅读 评论(0) 收藏

    这题实在不知道起啥名好了 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 懒得想背景故事了,开门见山. 有一个长度为n的整数数列A ...

  8. 2016年11月11日 星期五 --出埃及记 Exodus 20:2

    2016年11月11日 星期五 --出埃及记 Exodus 20:2 "I am the LORD your God, who brought you out of Egypt, out o ...

  9. Linux下常用的shell命令记录1

     硬件篇 CPU相关 lscpu #查看的是cpu的统计信息. cat /proc/cpuinfo #查看CPU信息详细信息,如每个CPU的型号,主频等 内存相关 free -m #概要查看内存情况 ...

  10. 关于myeclipse中maven项目转换相关设置

    关于myeclipse中maven项目转换相关设置 在myeclipse菜单中,Configure->Convert to Maven Project 这个菜单 如果没有的话,需要做如下设置: ...