POJ2455Secret Milking Machine[最大流 无向图 二分答案]

时间:2022-06-27 21:47:55
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


POJ2455Secret Milking Machine[最大流 无向图 二分答案]

奇怪的问题,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】&lbrack;Usaco2005 feb&rsqb;Secret Milking Machine 神秘的挤奶机 二分&plus;网络流最大流

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

  2. BZOJ 3993 Luogu P3324 &lbrack;SDOI2015&rsqb;星际战争 &lpar;最大流、二分答案&rpar;

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

  3. POJ 2112 Optimal Milking &lpar; 经典最大流 &amp&semi;&amp&semi; Floyd &amp&semi;&amp&semi; 二分 &rpar;

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

  4. &lbrack;Sdoi2013&rsqb;费用流(最大流,二分答案)

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

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

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

  6. poj2455Secret Milking Machine&lpar;二分&plus;最大流)

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

  7. BZOJ 1305&colon; &lbrack;CQOI2009&rsqb;dance跳舞 网络最大流&lowbar;二分答案&lowbar;建模

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

  8. POJ 2455 Secret Milking Machine(最大流&plus;二分)

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

  9. POJ 2455 Secret Milking Machine 【二分】&plus;【最大流】

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

随机推荐

  1. 【转】websocket协议规范

    在线版目录: 1.引言——WebSocket协议翻译 2.一致性要求——WebSocket协议翻译 3.WebSocket URI——WebSocket协议翻译 4.打开阶段握手——WebSocket ...

  2. Android -- 获取汉字的首字母

    转换                                                                                             获取一个汉 ...

  3. c语言输出可见字符

    #include <stdio.h> void main() { int i; //可见字符是32-126 ;i<;i++) { putchar(i); } getchar(); }

  4. &period;net简单页面后台绑定下拉框,按钮,分页 前台aspx页面

    一.aspx页面 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Updat ...

  5. C&num;程序设计六大原则记录

    本文目的在于记录,方便以后的回顾 http://www.uml.org.cn/sjms/201211023.asp 设计模式六大原则(1):单一职责原则 定义:不要存在多于一个导致类变更的原因.通俗的 ...

  6. Linq Take和Skip详解

    Take()方法的作用就是:从查询结果中提取前n个结果. Skip()方法正好是Take()方法的反面,它可以跳过前n个结果,返回剩余的结果. 例如:查找年龄最大的3个人 表Student的数据是 N ...

  7. 关于创建本地docker仓库

    从远程仓库中下载regitstry镜像文件,下载后运行命令即可:docker run -p 5000:5000 -d registry

  8. ASP&period;NET MVC和ASP&period;NET Core MVC中获取当前URL&sol;Controller&sol;Action (转载)

    ASP.NET MVC 一.获取URL(ASP.NET通用): [1]获取完整url(协议名+域名+虚拟目录名+文件名+参数) string url=Request.Url.ToString(); [ ...

  9. python打印列表的下标和值的例子:

    python打印列表的下标和值的例子: In [1]: list01=[1,4,5] In [10]: def funct01(ll):   ....:     for index,value in ...

  10. WorldWind源码剖析系列:可渲染对象类RenderableObject

    RenderableObject是WorldWind中所有需要渲染的对象的父类,继承了接口IRenderable和Icomparable.其派生类体系如下所示.RenderableObject的成员如 ...