Secret Milking Machine
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 11865   Accepted: 3445

Description

Farmer John is constructing a new milking machine and wishes to keep it secret as long as possible. He has hidden in it deep within his farm and needs to be able to get to the machine without being detected. He must make a total of T (1 <= T <= 200) trips to the machine during its construction. He has a secret tunnel that he uses only for the return trips.

The farm comprises N (2 <= N <= 200) landmarks (numbered 1..N)
connected by P (1 <= P <= 40,000) bidirectional trails (numbered 1..P) and
with a positive length that does not exceed 1,000,000. Multiple trails might
join a pair of landmarks.

To minimize his chances of detection, FJ knows
he cannot use any trail on the farm more than once and that he should try to use
the shortest trails.

Help FJ get from the barn (landmark 1) to the
secret milking machine (landmark N) a total of T times. Find the minimum
possible length of the longest single trail that he will have to use, subject to
the constraint that he use no trail more than once. (Note well: The goal is to
minimize the length of the longest trail, not the sum of the trail lengths.)

It is guaranteed that FJ can make all T trips without reusing a
trail.

Input

* Line 1: Three space-separated integers: N, P, and T

* Lines 2..P+1: Line i+1 contains three space-separated integers, A_i,
B_i, and L_i, indicating that a trail connects landmark A_i to landmark B_i with
length L_i.

Output

* Line 1: A single integer that is the minimum
possible length of the longest segment of Farmer John's route.

Sample Input

7 9 2
1 2 2
2 3 5
3 7 5
1 4 1
4 3 1
4 5 7
5 7 1
1 6 3
6 7 3

Sample Output

5

Hint

Farmer John can travel trails 1 - 2 - 3 - 7 and 1 - 6 - 7. None of the trails travelled exceeds 5 units in length. It is impossible for Farmer John to travel from 1 to 7 twice without using at least one trail of length 5.

Huge input data,scanf is recommended.

Source


奇怪的问题,bfs处理e[i].w<=mid就不对,每次重新建图就对了,不知道为什么(貌似因为f没有清0)

无向图的处理,反向边的容量也是c

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=,INF=1e9;
int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
int n,m,T,u,v,w,s,t;
struct edge{
int v,ne,w,c,f;
}e[N*N<<];
struct data{
int u,v,w;
}a[N*N];
int h[N],cnt=;
inline void ins(int u,int v,int w,int c){//printf("ins %d %d %d\n",u,v,w);
cnt++;
e[cnt].v=v;e[cnt].c=c;e[cnt].f=;e[cnt].w=w;e[cnt].ne=h[u];h[u]=cnt;
cnt++;
e[cnt].v=u;e[cnt].c=c;e[cnt].f=;e[cnt].w=w;e[cnt].ne=h[v];h[v]=cnt;
} int cur[N];
int q[N],head,tail,vis[N],d[N]; void build(int mid){
cnt=;
memset(h,,sizeof(h));
for(int i=;i<=m;i++) if(a[i].w<=mid) ins(a[i].u,a[i].v,a[i].w,);
}
bool bfs(int mid){//应该可以这里处理mid
memset(vis,,sizeof(vis));
memset(d,,sizeof(d));
head=tail=;
q[tail++]=s;d[s]=;vis[s]=;
while(head!=tail){
int u=q[head++];
for(int i=h[u];i;i=e[i].ne){
int v=e[i].v;
if(!vis[v]&&e[i].f<e[i].c){
q[tail++]=v;vis[v]=;
d[v]=d[u]+;
if(v==t) return ;
}
}
}
return ;
}
int dfs(int u,int a){//printf("dfs %d %d\n",u,a);
if(u==t||a==) return a;
int flow=,f;
for(int &i=cur[u];i;i=e[i].ne){
int v=e[i].v;
if(d[v]==d[u]+&&(f=dfs(v,min(a,e[i].c-e[i].f)))>){
flow+=f;
e[i].f+=f;
e[((i-)^)+].f-=f;
a-=f;
if(a==) break;
}
}
return flow;
}
int dinic(int mid){
int flow=;
while(bfs(mid)){
for(int i=s;i<=t;i++) cur[i]=h[i];
flow+=dfs(s,INF);
}
//printf("flow %d\n",flow);
return flow;
} int main(){
n=read();m=read();T=read();s=;t=n;
int l=INF,r=,ans=INF;
for(int i=;i<=m;i++){
u=read();v=read();w=read(); r=max(r,w);l=min(l,w);
//ins(u,v,w,1);
a[i].u=u;a[i].v=v;a[i].w=w;
}
while(l<=r){
int mid=(l+r)>>;//printf("hi %d %d %d\n",l,r,mid);
build(mid);
if(dinic(mid)>=T) ans=min(ans,mid),r=mid-;
else l=mid+;
}
printf("%d",ans);
}
 
 

POJ2455Secret Milking Machine[最大流 无向图 二分答案]的更多相关文章

  1. 【bzoj1733】[Usaco2005 feb]Secret Milking Machine 神秘的挤奶机 二分+网络流最大流

    题目描述 Farmer John is constructing a new milking machine and wishes to keep it secret as long as possi ...

  2. BZOJ 3993 Luogu P3324 [SDOI2015]星际战争 (最大流、二分答案)

    字符串终于告一段落了! 题目链接: (bzoj) https://www.lydsy.com/JudgeOnline/problem.php?id=3993 (luogu) https://www.l ...

  3. POJ 2112 Optimal Milking ( 经典最大流 && Floyd && 二分 )

    题意 : 有 K 台挤奶机器,每台机器可以接受 M 头牛进行挤奶作业,总共有 C 头奶牛,机器编号为 1~K,奶牛编号为 K+1 ~ K+C ,然后给出奶牛和机器之间的距离矩阵,要求求出使得每头牛都能 ...

  4. [Sdoi2013]费用流(最大流,二分答案)

    前言 网络流的练习为什么我又排在最后啊!!! Solution 我们先来挖掘一个式子: \[ ab+cd>ad+bc(a<c,b<d) \] 这个的证明很显然对吧. 然后就考虑最优策 ...

  5. POJ 2391 多源多汇拆点最大流 +flody+二分答案

    题意:在一图中,每个点有俩个属性:现在牛的数量和雨棚大小(下雨时能容纳牛的数量),每个点之间有距离, 给出牛(速度一样)在顶点之间移动所需时间,问最少时间内所有牛都能避雨. 模型分析:多源点去多汇点( ...

  6. poj2455Secret Milking Machine(二分+最大流)

    链接 二分距离,小于当前距离的边容量+1,使最后流>=t 注意 会有重边 #include <iostream> #include<cstdio> #include< ...

  7. BZOJ 1305: [CQOI2009]dance跳舞 网络最大流_二分答案_建模

    Description 一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲.有一些男孩女孩相互喜欢,而其他相互不喜欢(不会 ...

  8. POJ 2455 Secret Milking Machine(最大流+二分)

    Description Farmer John is constructing a new milking machine and wishes to keep it secret as long a ...

  9. POJ 2455 Secret Milking Machine 【二分】+【最大流】

    <题目链接> 题目大意: FJ有N块地,这些地之间有P条双向路,每条路的都有固定的长度l.现在要你找出从第1块地到第n块地的T条不同路径,每条路径上的路段不能与先前的路径重复,问这些路径中 ...

随机推荐

  1. PetaPoco4.0的事务为什么不会回滚

    using (var srop=DbHelper.CurrentDb.GetTransaction()) { ID = bp.AddModel(model).ToStr(); #region 参与楼盘 ...

  2. 十二种获取Spring的上下文环境ApplicationContext的方法

    转载:https://my.oschina.net/u/2391658/blog/729414

  3. 天津政府应急系统之GIS一张图(arcgis api for flex)讲解(十一)路径导航模块

    config.xml文件的配置如下: <widget label="路径导航" icon="assets/images/lujingdaohang.png" ...

  4. HTML5学习之 开发工具

    Notepad++.Editplus 是常用的开发编辑器.这些在Window系统下,比较容易找到,但是在MAC系统下,有的是收费的,有的是不支持.我开发的时候,用的是TextWrangler,如图: ...

  5. WinForm中实现播放mp3 、mp4文件

    来自:http://www.cnblogs.com/duanchen/p/4445478.html 1.在Vs2012 工具箱右键-->"选择项"-->"Co ...

  6. C#中的泛型

    写在前面:好几个月没更新了,这些天换了份工作,原来的公司出了很多事所以辞职了.这篇文章写的超级好,让我终于明白了困扰在我心里好久的C#泛型的概念,不仅收藏了,还手动转发一下 哈哈哈~ 1.1 C#中的 ...

  7. 如何将github上的 lib fork之后通过podfile 改变更新源到自己fork的地址

    解决办法: http://stackoverflow.com/questions/20936885/cocoapods-and-github-forks 就是fork完后,提交更改到自己的github ...

  8. IOS开发基础知识--碎片20

    1:view中的clipsTobounds属性 iew2添加view1到中,如果view2大于view1,或者view2的坐标不全在view1的范围内,view2是盖着view1的,意思就是超出的部份 ...

  9. ObjectAnimator属性动画应用demo

    感谢慕课网--eclipse_xu 布局文件:activity_main.xml <FrameLayout xmlns:android="http://schemas.android. ...

  10. 转载文档:Storm实战常见问题及解决方案

    该文档为实实在在的原创文档,转载请注明: http://blog.sina.com.cn/s/blog_8c243ea30101k0k1.html 类型 详细 备注 该文档是群里几个朋友在storm实 ...