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. Python 3.4 Library setup

    matplotlib:  https://pypi.python.org/pypi/matplotlib/1.4.3 Unofficial Windows Binaries for Python Ex ...

  2. Linux解决乱码问题

    主要的关注点是本身文件的编码和Linux的编码是否相同, 如果不相同的话,那么修改 例如: 就OK了,如果还是有问题的话,那么就查看一下连接工具的编码是否设置的有问题. 一般情况下,主要注意这些问题, ...

  3. ftp 根据特定正则匹配文件名 下载到本地 并且上传文件到ftp java *** 最爱那水货

    /** * 建立FTP链接,FTP服务器地址.端口.登陆用户信息都在配置里配置即可. * @throws IOException */ public boolean connectFtp(String ...

  4. JAVA简单工厂模式(从现实生活角度理解代码原理)

    简单工厂模式(Simple Factory),说他简单是因为我们可以将此模式比作一个简单的民间作坊,他们只有固定的生产线生产固定的产品.也可以称他为静态工厂设计模式,类似于之前提到过静态代理设计模式, ...

  5. Linux下安装使用Solr

    Linux下安装使用Solr 1.首先下载Solr.mmseg4j分词包.tomcat并解压,这用google.百度都可以搜索得到下载地址. 2.因为要使用到中文分词,所以要设置编码,进入tomcat ...

  6. 关于json序列化循环引用导致出错

    以下是错误信息: Caused by: java.lang.IllegalStateException: circular reference error  Offending field: meth ...

  7. android adb pull push

    adb命令下pull的作用是从手机端向电脑端拷文件. adb pull /storage/emulated/0/Download/**.apk  /Users/edwin/Downloads adb命 ...

  8. Echarts xAxis boundaryGap

    Echarts  xAxis----->boundaryGap: false 坐标轴两边留白策略,类目轴和非类目轴的设置和表现不一样. 类目轴中 boundaryGap 可以配置为 true 和 ...

  9. yii2 左侧菜单子级无法高亮的问题

    作者:白狼 出处:http://www.manks.top/question/20160508000001.html 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出 ...

  10. C# 6.0新特性---语法糖

    转载:http://www.cnblogs.com/TianFang/p/3928172.html 所谓语法糖就是在编译器里写做文章,达到简化代码书写的目的,要慎重使用,省略过多不易理解. NULL检 ...