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

Destroying the bus stations

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2651    Accepted Submission(s): 891

Problem Description
Gabiluso
is one of the greatest spies in his country. Now he’s trying to
complete an “impossible” mission ----- to make it slow for the army of
City Colugu to reach the airport. City Colugu has n bus stations and m
roads. Each road connects two bus stations directly, and all roads are
one way streets. In order to keep the air clean, the government bans all
military vehicles. So the army must take buses to go to the airport.
There may be more than one road between two bus stations. If a bus
station is destroyed, all roads connecting that station will become no
use. What’s Gabiluso needs to do is destroying some bus stations to make
the army can’t get to the airport in k minutes. It takes exactly one
minute for a bus to pass any road. All bus stations are numbered from 1
to n. The No.1 bus station is in the barrack and the No. n station is in
the airport. The army always set out from the No. 1 station.
No.1
station and No. n station can’t be destroyed because of the heavy guard.
Of course there is no road from No.1 station to No. n station.

Please help Gabiluso to calculate the minimum number of bus stations he must destroy to complete his mission.

 
Input
There are several test cases. Input ends with three zeros.

For each test case:

The first line contains 3 integers, n, m and k. (0< n <=50, 0< m<=4000, 0 < k < 1000)
Then
m lines follows. Each line contains 2 integers, s and f, indicating
that there is a road from station No. s to station No. f.

 
Output
For each test case, output the minimum number of stations Gabiluso must destroy.
 
Sample Input
5 7 3
1 3
3 4
4 5
1 2
2 5
1 4
4 5
0 0 0
 
Sample Output
2
 
Source
 
题意:

给定n个点, m条有向边 ,k

下面m条有向边

问删最少几个点使得1-n的最短路>k

分析:

其证明还没看懂,先做了再说咯。证明在紫书370,写一下结论:在增广路算法结束时,f是s-t最大流,(S,T)是最小割。
然后问了一下阳哥,记录几个结论,最大流=最小割(边)=最小割(点)。
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <queue>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = + ;
int k; struct Edge
{
int from,to,cap,flow,cost;
Edge() {}
Edge(int a,int b,int c,int d,int e):from(a),to(b),cap(c),flow(d),cost(e) {}
}; struct MCMF
{
int n,m,s,t;
vector<Edge> edges;
vector<int> g[maxn];
int inq[maxn];
int d[maxn];
int p[maxn];
int a[maxn]; void init(int n)
{
this->n =n;
for(int i=; i<n; i++)g[i].clear();
edges.clear();
}
void addedge(int from,int to,int cap,int cost)
{
Edge e1= Edge(from,to,cap,,cost), e2= Edge(to,from,,,-cost);
edges.push_back(e1);
edges.push_back(e2);
m=edges.size();
g[from].push_back(m-);
g[to].push_back(m-);
}
bool spfa(int s,int t, int & flow,int & cost)
{
for(int i=; i<n; i++)
d[i]=INF;
memset(inq,,sizeof(inq));
d[s]=;
inq[s]=;
p[s]=;
a[s]=INF;
queue<int>q;
q.push(s);
while(!q.empty())
{
int u=q.front();
q.pop();
inq[u]=;
for(int i=; i<g[u].size(); i++)
{
Edge & e = edges[g[u][i]];
if(e.cap>e.flow && d[e.to]>d[u]+e.cost)
{
d[e.to]=d[u]+e.cost;
p[e.to]=g[u][i];
a[e.to]=min(a[u],e.cap-e.flow);
if(!inq[e.to])
{
q.push(e.to);
inq[e.to]=;
}
}
}
}
if(d[t]>k)
return false;
if(d[t]==INF)
return false; flow+=a[t];
cost+=a[t]*d[t];
for(int u=t; u!=s; u=edges[p[u]].from)
{
edges[p[u]].flow +=a[t];
edges[p[u]^].flow-=a[t];
}
return true;
} int MincostMaxflow(int s,int t)
{
int flow=,cost =;
while(spfa(s,t,flow,cost));
return flow;
}
} sol; int main()
{
freopen("input.txt","r",stdin);
int n,m;
while(scanf("%d%d%d",&n,&m,&k))
{
int s = ,t = *n+;
if(n==&&m==&&k==) break;
int u,v;
sol.init(n*+);
for(int i=; i<=n; i++)
sol.addedge(i+n,i,,); sol.addedge(,+n,INF,);
sol.addedge(n,*n,INF,);
sol.addedge(,,INF,);
sol.addedge(*n,t,INF,);
for(int i=; i<m; i++)
{
scanf("%d%d",&u,&v);
sol.addedge(u,v+n,INF,);
}
printf("%d\n",sol.MincostMaxflow(s,t));
}
return ;
}

HDU(2485),最小割最大流的更多相关文章

  1. hdu 2485(最小费用最大流)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2485 思路:题目的意思是删除最少的点使1,n的最短路大于k.将点转化为边,容量为1,费用为0,然后就是 ...

  2. hdu4289 最小割最大流 (拆点最大流)

    最小割最大流定理:(参考刘汝佳p369)增广路算法结束时,令已标号结点(a[u]>0的结点)集合为S,其他结点集合为T=V-S,则(S,T)是图的s-t最小割. Problem Descript ...

  3. 【BZOJ-1797】Mincut 最小割 最大流 + Tarjan + 缩点

    1797: [Ahoi2009]Mincut 最小割 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1685  Solved: 724[Submit] ...

  4. BZOJ-1001 狼抓兔子 (最小割-最大流)平面图转对偶图+SPFA

    1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec Memory Limit: 162 MB Submit: 14686 Solved: 3513 [Submit][ ...

  5. hdu1569 方格取数(2) 最大点权独立集=总权和-最小点权覆盖集 (最小点权覆盖集=最小割=最大流)

    /** 转自:http://blog.csdn.net/u011498819/article/details/20772147 题目:hdu1569 方格取数(2) 链接:https://vjudge ...

  6. BZOJ1001:狼抓兔子(最小割最大流+vector模板)

    1001: [BeiJing2006]狼抓兔子 Description 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的,而且现在的兔子还比较笨, ...

  7. HDU1565 方格取数(1) —— 状压DP or 插头DP(轮廓线更新) or 二分图点带权最大独立集(最小割最大流)

    题目链接:https://vjudge.net/problem/HDU-1565 方格取数(1) Time Limit: 10000/5000 MS (Java/Others)    Memory L ...

  8. hdu 3691最小割将一个图分成两部分

    转载地址:http://blog.csdn.net/xdu_truth/article/details/8104721 题意:题给出一个无向图和一个源点,让你求从这个点出发到某个点最大流的最小值.由最 ...

  9. 最小割最大流定理&残量网络的性质

    最小割最大流定理的内容: 对于一个网络流图 $G=(V,E)$,其中有源点和汇点,那么下面三个条件是等价的: 流$f$是图$G$的最大流 残量网络$G_f$不存在增广路 对于$G$的某一个割$(S,T ...

  10. Destroying The Graph 最小点权集--最小割--最大流

    Destroying The Graph 构图思路: 1.将所有顶点v拆成两个点, v1,v2 2.源点S与v1连边,容量为 W- 3.v2与汇点连边,容量为 W+ 4.对图中原边( a, b ), ...

随机推荐

  1. SQL语句执行时间测试

    select getdate()--开始执行时间   要执行的SQL语句 select getdate() --结束时间

  2. G面经prepare: Pattern Match

    设定一个pattern 把 'internationalization' 变成 'i18n', 比如word是house,pattern可以是h3e, 3se, 5, 1o1s1等, 给pattern ...

  3. acm算法模板(1)

    1. 几何 4 1.1 注意 4 1.2 几何公式 4 1.3 多边形 6 1.4 多边形切割 9 1.5 浮点函数 10 1.6 面积 15 1.7 球面 16 1.8 三角形 17 1.9 三维几 ...

  4. 记录把方法添加到 JavaScript 对象不明白的地方

    <!DOCTYPE html> <html> <body> <script> function person(firstname,lastname,ag ...

  5. Java IO总结之缓冲读入文件

    package com.io; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException ...

  6. C# 语音识别

    利用微软操作系统自动的语音识别功能,读取信息. 1.  在项目中添加  ""  引用 2.  引入命名空间:   using SpeechLib; 3.   读取的代码: Spee ...

  7. 【linux】终端直接执行py文件,不需要python命令

    先将终端所在路径切换到python脚本文件的目录下然后给脚本文件运行权限,一般755就OK,如果完全是自己的私人电脑,也不做服务器什么的,给777的权限问题也不大(具体权限含义参考chmod指令的介绍 ...

  8. C++线性方程求解

    介绍 程序SolveLinearEquations解决联立方程.该方案需要一个文本文件,其中包含输入和输出方程解决.这个项目是几年前我写在C#中http://www.codeproject.com/A ...

  9. git-gui

    使用Git.Git GUI和TortoiseGit http://zengrong.net/post/1722.htm 但云桌面不能安装,则TortoiseGit不能使用! 只能想到用totalcmd ...

  10. redmine plugin

    http://wangsheng2008love.blog.163.com/blog/static/78201689200992064615770/