题意:

  最少需要几个点才能使得有向图中1->n的距离大于k。

分析:

  删除某一点的以后,与它相连的所有边都不存在了,相当于点的容量为1。但是在网络流中我们只能直接限制边的容量。所以需要拆点来完成对的点容量的限制。对于边i -> j,先建边i ->i',再建i'->j。i ->i'只能建一次,容量为1,费用为0。i'->j的容量是INF。此题中因为已经有源点,所以源点(1)不能限制容量。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N =, M=,INF=0x3f3f3f3f;
struct node
{
int to, next, c ,f;//c是容量,f是费用
}edge[M];
int head[N],dis[N],load[N],p[N];
bool vis[N];
int tot,flow,ans,D;
bool spfa(int S, int E,int n)
{
int que[N*],qout,qin;
memset(vis,,sizeof(vis));
memset(load,-,sizeof(load));
memset(p,-,sizeof(p));
for(int i=;i<=n;i++)
dis[i]=INF;
qin=qout=;
que[qin++]=S;
dis[S]=;
vis[S]=;
while(qin!=qout)
{
int u=que[qout++];
vis[u]=;
for(int i=head[u];i!=-;i=edge[i].next)
{
if(edge[i].c)
{
int v=edge[i].to;
if(dis[v]-dis[u]>edge[i].f)
{
dis[v]=dis[u]+edge[i].f;
p[v]=u;
load[v]=i;
if(!vis[v])
{
vis[v]=;
que[qin++]=v;
}
}
}
}
}
if(dis[E]>D) return ;
return ;
}
void MCF(int S, int E,int n)
{
int u,mn;
flow=ans=;
while(spfa(S,E,n))
{
u=E; mn=INF;
while(p[u]!=-)
{
mn=min(edge[load[u]].c, mn);
u=p[u];
}
u=E;
while(p[u]!=-)
{
edge[load[u]].c-=mn;
edge[load[u]^].c+=mn;
u=p[u];
}
ans+=dis[E]*mn;
flow+=mn;
}
}
void addedge(int a,int b,int c,int d)
{
edge[tot].to=b;edge[tot].c=c;edge[tot].f=d;
edge[tot].next=head[a];head[a]=tot++;
edge[tot].to=a;edge[tot].c=;edge[tot].f=-d;
edge[tot].next=head[b];head[b]=tot++;
}
void init()
{
tot=;
memset(head,-,sizeof(head));
}
int main()
{
//freopen("test.txt","r",stdin);
int n,m,i,j,k;
while(scanf("%d%d%d",&n,&m,&D)!=EOF&&n)
{
init();
while(m--)
{
scanf("%d%d",&i,&j);
if(i!=) addedge(i+n,j,INF,);
else addedge(i,j,INF,);
}
for(i=;i<n;i++) addedge(i,i+n,,);
MCF(,n,*n);
printf("%d\n",flow);
}
return ;
}

hdu 2485 Destroying the bus stations 最小费用最大流的更多相关文章

  1. HDU 2485 Destroying the bus stations(费用流)

    http://acm.hdu.edu.cn/showproblem.php?pid=2485 题意: 现在要从起点1到终点n,途中有多个车站,每经过一个车站为1时间,现在要在k时间内到达终点,问至少要 ...

  2. HDU 2485 Destroying the bus stations(!最大流∩!费用流∩搜索)

    Description Gabiluso is one of the greatest spies in his country. Now he’s trying to complete an “im ...

  3. 图论--网络流--最小割 HDU 2485 Destroying the bus stations(最短路+限流建图)

    Problem Description Gabiluso is one of the greatest spies in his country. Now he's trying to complet ...

  4. HDU 2485 Destroying the bus stations (IDA*+ BFS)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2485 题意:给你n个点,m条相连的边,问你最少去掉几个点使从1到n最小路径>=k,其中不能去掉1, ...

  5. HDU 2485 Destroying the bus stations

    2015 ACM / ICPC 北京站 热身赛 C题 #include<cstdio> #include<cstring> #include<cmath> #inc ...

  6. SCU3033 Destroying a Painting(最小费用最大流)

    题目大概说有一个有n*m个格子的画板,画板上每个格子都有颜色,现在要把所有格子的颜色改成红.绿或者蓝,改变的代价是二者RGB值的曼哈顿距离,还要求红绿蓝格子个数的最大值和最小值要尽可能接近,问最少的代 ...

  7. HDUOJ----2485 Destroying the bus stations(2008北京现场赛A题)

    Destroying the bus stations                                                                          ...

  8. hdu 2686 Matrix 最小费用最大流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2686 Yifenfei very like play a number game in the n*n ...

  9. hdu 1533 Going Home 最小费用最大流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1533 On a grid map there are n little men and n house ...

随机推荐

  1. json简介及josn数组中取字符

    1.json字符串就是字符串,只不过格式是Json格式的,以键值对的形式存在,键和值可以是字符串,数字,空值,数组等. json对象在花括号中书写,一个json对象包含多个键值对,json对象以花括号 ...

  2. 【转载】Java 反射详解

    目录 1.什么是反射? 2.反射能做什么? 3.反射的具体实现 4.根据反射获取父类属性 4.反射总结 反射反射,程序员的快乐! 1.什么是反射? Java反射就是在运行状态中,对于任意一个类,都能够 ...

  3. 修复Thinkphp框架5.0和5.1版本的远程代码执行安全漏洞

    由于框架对控制器名没有进行足够的检测会导致在没有开启强制路由的情况下可能的getshell漏洞.最直接的影响为index.php直接被篡改成首页html的内容! 5.0版本 thinkphp/libr ...

  4. [poj1325] Machine Schedule (二分图最小点覆盖)

    传送门 Description As we all know, machine scheduling is a very classical problem in computer science a ...

  5. POJ 1703 Find them, Catch them(并查集高级应用)

    手动博客搬家:本文发表于20170805 21:25:49, 原地址https://blog.csdn.net/suncongbo/article/details/76735893 URL: http ...

  6. 【ZOJ 4067】Books

    [链接] 我是链接,点我呀:) [题意] [题解] 统计a中0的个数cnt0 然后m减去cnt0 因为这cnt0个0是一定会取到的. 如果m==0了 那么直接找到数组中的最小值mi 输出mi-1就好 ...

  7. HDU 2415 Bribing FIPA

    Bribing FIPA Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original I ...

  8. HDU 4359 Easy Tree DP?

    Easy Tree DP? Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  9. dubbo-源码阅读之bean装配过程(四)

    Spring自定义schema 我们再使用dubbo进行时 会经常看到这样的标签 <!--开启注解扫描--> <context:component-scan base-package ...

  10. 苦酒入喉心作痛,红酒入鹅鹅想哭——震惊!勒索病毒想哭靠wine感染了Ubuntu16.04

    都说linux能免疫win的病毒来着…… 今天作死,逛贴吧时好奇下载了一个想哭2.0 (http://pan.baidu.com/share/link?shareid=1393367320&u ...