题目链接: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. PostgreSQL/bin

    pg_receivexlog pg_receivexlog—以流的方式从一个PostgreSQL集簇得到事务日志 pg_receivexlog被用来从一个运行着的PostgreSQL集簇以流的方式得到 ...

  2. sublime text常用插件

    这个比较重要,不会装插件的时候找了好久 sublime text常用插件 1.插件的安装方法 第一种:用package control 这个是用来管理插件的,必备啊,安装package control ...

  3. Lintcode: Single Number III

    Given 2*n + 2 numbers, every numbers occurs twice except two, find them. Example Given [1,2,2,3,4,4, ...

  4. .NET: 防止多个应用程序同时开

    用到了Mutex这个类,直接看代码~ using System; using System.Collections.Generic; using System.Linq; using System.W ...

  5. 认识javascript

    javascript小知识 www.phonegap.com(跨平台开发框架) Cocos2d-Html5(WebGL渲染  javascript语言) creatjs.com(融合了flash动画的 ...

  6. 6. 星际争霸之php设计模式--建造器模式

    题记==============================================================================本php设计模式专辑来源于博客(jymo ...

  7. 「LAMP」在ubuntu及其衍生版上 安装LAMP

    在Ubuntu上安装LAMP 此种方法在Linux Mint 13/14/15/16/17.Ubuntu 12.10(Quantal Quetzal)和Ubuntu 13.04 Raring Ring ...

  8. Entity Framework 无法对没有主键的视图映射实体的解决办法

    我们在使用Entity Framework的时候经常会把数据库中的某一个视图映射为EF的实体,但是如果数据库视图中的列没有包含表的主键列,EF会报出警告说视图没有主键,导致视图映射为实体失败,错误如下 ...

  9. ckeditor添加插入flv视频的插件

    首发:个人博客,更新&纠错&回复 昨天写在网页中播放flv的博文的时候,想在博文中插入视频,但是发现无法实现.因为用的编辑器是ckeditor,决定自己写个插件插入视频.官方的教程在这 ...

  10. DLL:加载错误

    一:试图加载格式不正确的程序 把目标平台Any CPU 设置为X86: