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. 各种类型转换为字符串类型(ToString())

    更详细请参考:http://blog.csdn.net/wanzhuan2010/article/details/8478904 // C 货币 2.5.ToString("C") ...

  2. C#中对象,字符串,dataTable、DataReader、DataSet,对象集合转换成Json字符串方法。

    C#中对象,字符串,dataTable.DataReader.DataSet,对象集合转换成Json字符串方法. public class ConvertJson { #region 私有方法 /// ...

  3. java servlet 几种页面跳转的方法及传值

    java servlet 几种页面跳转的方法及传值   java web 页面之间传值有一下这几种方式1.form 表单传递参数2.url地址栏传递参数3.session4.cookie5.appli ...

  4. Linux tree命令

    Linux tree命令用于以树状图列出目录的内容. 执行tree指令,它会列出指定目录下的所有文件,包括子目录里的文件. 语法 tree [-aACdDfFgilnNpqstux][-I <范 ...

  5. java静态方法调用&&构造函数&&静态块

    静态方法,也就是使用static声明的方法,在虚拟机启动加载类的时候就进行了创建,所以使用到静态方法时,直接使用类名点静态方法即可调用.java在执行静态方法前,不会调用构造函数:构造函数是在实例化j ...

  6. iframe高度自适应

    前两天在网上看到了一道面试题,问iframe高度自适应的问题.发现自己之前几乎没有关注过iframe的问题,所以在这里记录一下. 原题目是: 页面A的域名是:http://www.taobao.com ...

  7. jquery获取关于宽度和高度的尺寸问题

    作者原创,转载请出名出处! console.log("可视区高度:"+$(window).height()); console.log("可视区宽度:"+$(w ...

  8. iOS - 详细理解KVC与KVO

    详细理解KVC与KVO 在面试的时候,KVC与KVO有些时候还是会问到的,并且他们都是Objective C的关键概念,在这里我们先做一个简单地介绍: (一)KVC: KVC即指:NSKeyValue ...

  9. Linux0.11内核--缓冲区机制大致分析

    文件系统的文件太多,而且是照搬的MINIX的文件系统,不想继续分析下去了.缓冲区机制和文件系统密切相关,所以这里就简单分析一下缓冲区机制. buffer.c 程序用于对高速缓冲区(池)进行操作和管理. ...

  10. 遇到别人留下的storyboard的,你需要一个引导图,但是不知道怎么跳转.

    首先在AppDeledate.m文件里是这样. { self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds] ...