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.

约翰正在制造一台新型的挤奶机,但他不希望别人知道.他希望尽可能久地隐藏这个秘密.他把挤奶机藏在他的农场里,使它不被发现.在挤奶机制造的过程中,他需要去挤奶机所在的地方T(1≤T≤200)次.他的农场里有秘密的地道,但约翰只在返回的时候用它.农场被划分成N(2≤N≤200)块区域,用1到200标号.这些区域被P(1≤P≤40000)条道路连接,每条路有一个小于10^6的长度L.两块区域之间可能有多条道路连接.为了减少被发现的可能,约翰不会两次经过农场上的任何一条道路.当然了,他希望走最短的路. 请帮助约翰寻找这T次从仓库走到挤奶机所在地的路线.仓库是区域1,挤奶机所在地是区域N.我们现在要求的是约翰经过的这些道路中最长的路的长度最小是多少,当然他不能重复走某一条路.请注意,我们要求的不是最短的总路程长度,而是所经过的直揍连接两个区域的道路中最长的道路的最小长度. 数据保证约翰可以找到T条没有重复的从仓库到挤奶机所在区域的路.

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.

    第1行是3个整数N、P和T,用空格隔开.
    第2到P+1行,每行包括3个整数,Ai,Bi,Li.表示区域Ai、Bi之间有一条长度为Li的道路.

Output

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

 
输出只有一行,包含一个整数,即约翰经过的这些道路中最长的路的最小长度.
 

可以二分这个最长长度的上限 $mid$,每次只加入长度小于等于 $mid$ 的边

剩下的问题就是要找到 $T$ 个互不重叠的 '环'

跑一个最大流就好了,若流量大于等于 $T$,则符合要求

#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#define ll long long
#define setIO(s) freopen(s".in","r",stdin)
#define maxn 100000
#define inf 230
using namespace std;
int n,m,cc,S,T;
struct Dinic {
struct Edge {
int from,to,cap;
Edge(int from=0,int to=0,int cap=0):from(from),to(to),cap(cap){}
};
queue<int>Q;
vector<Edge>edges;
vector<int>G[300];
int current[300],d[300],vis[300];
void addedge(int u,int v,int c) {
edges.push_back(Edge(u,v,c));
edges.push_back(Edge(v,u,0));
int o=edges.size();
G[u].push_back(o-2);
G[v].push_back(o-1);
}
int BFS() {
memset(vis,0,sizeof(vis)), memset(d,0,sizeof(d));
vis[S]=1,d[S]=0;
Q.push(S);
while(!Q.empty()) {
int u=Q.front(); Q.pop();
for(int i=0;i<G[u].size();++i) {
Edge e=edges[G[u][i]];
if(e.cap>0 && !vis[e.to]) {
vis[e.to]=1, d[e.to]=d[u]+1;
Q.push(e.to);
}
}
}
return vis[T];
}
int dfs(int x,int cur) {
if(x==T) return cur;
int f,flow=0;
for(int i=current[x];i<G[x].size();++i) {
current[x]=i;
Edge e=edges[G[x][i]];
if(d[e.to]==d[x]+1 && e.cap > 0) {
f=dfs(e.to,min(cur, e.cap));
if(f) {
cur-=f, flow+=f, edges[G[x][i]].cap-=f, edges[G[x][i]^1].cap+=f;
if(cur<=0) return flow;
}
}
}
return flow;
}
int maxflow() {
int re=0;
while(BFS()) memset(current,0,sizeof(current)),re+=dfs(S,inf);
return re;
}
void re() {
edges.clear();
for(int i=0;i<300;++i) G[i].clear();
}
}net;
struct Node {
int u,v,c;
}nd[maxn];
bool cmp(Node a,Node b) {
return a.c < b.c;
}
int check(int t) {
net.re();
for(int i=1;i<=t;++i) {
net.addedge(nd[i].u,nd[i].v,1);
net.addedge(nd[i].v,nd[i].u,1);
}
return net.maxflow() >= cc;
}
int main() {
// setIO("input");
scanf("%d%d%d",&n,&m,&cc);
for(int i=1;i<=m;++i) scanf("%d%d%d",&nd[i].u,&nd[i].v,&nd[i].c);
sort(nd+1,nd+1+m,cmp);
int l=1,r=m,mid,ans=0;
S=1,T=n;
while(l<=r) {
mid=(l+r)>>1;
if(check(mid)) ans=mid, r=mid-1;
else l=mid+1;
}
printf("%d\n",nd[ans].c);
return 0;
}

  

BZOJ 1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机 网络流 + 二分答案的更多相关文章

  1. BZOJ 1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机

    Description 约翰正在制造一台新型的挤奶机,但他不希望别人知道.他希望尽可能久地隐藏这个秘密.他把挤奶机藏在他的农场里,使它不被发现.在挤奶机制造的过程中,他需要去挤奶机所在的地方T(1≤T ...

  2. [bzoj1733][Usaco2005 feb]Secret Milking Machine 神秘的挤奶机_网络流

    [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机 题目大意:约翰正在制造一台新型的挤奶机,但他不希望别人知道.他希望尽可能久地隐藏这个秘密.他把挤奶机藏在他的农 ...

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

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

  4. [BZOJ 1733] [Usaco2005 feb] Secret Milking Machine 【二分 + 最大流】

    题目链接:BZOJ - 1733 题目分析 直接二分这个最大边的边权,然后用最大流判断是否可以有 T 的流量. 代码 #include <iostream> #include <cs ...

  5. BZOJ1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机

    n<=200个点m<=40000条边无向图,求   t次走不经过同条边的路径从1到n的经过的边的最大值   的最小值. 最大值最小--二分,t次不重边路径--边权1的最大流. #inclu ...

  6. POJ 2455 Secret Milking Machine(搜索-二分,网络流-最大流)

    Secret Milking Machine Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9658   Accepted: ...

  7. POJ2455 Secret Milking Machine

    Secret Milking Machine Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12324   Accepted ...

  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. BZOJ 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛( 二分答案 )

    最小最大...又是经典的二分答案做法.. -------------------------------------------------------------------------- #inc ...

随机推荐

  1. (转)Eclipse - CDT使用GDB调试C++的问题-无源文件命名(No source file named)

    http://tech.ddvip.com/2014-09/1411618782213496.html Eclipse CDT调试C++, 使用的Unix的调试器GDB; 由于在Unix下, 文件的目 ...

  2. python winsound模块

    (目标:出现交易下单.结束成交.数据中断等信号的时候,PC 发出声音提醒.) python winsound模块 winsound是Python的内置包,无需下载.可以直接通过 import wins ...

  3. FTP-学习笔记(1)

    1.简单的SFTP.FTP文件上传下载 SftpTools.java package com.lfy.mian; import com.jcraft.jsch.*; import java.io.Fi ...

  4. Android的Monkey和MonkeyRunner

    本文部分解释性语段摘自网络百科或其它BLOG,语句内容网络随处可见,也不知道谁是初始原创,便不再署名出处,如有雷同,还请见谅. Monkey 什么是Monkey Monkey是Android中的一个命 ...

  5. java基础笔记(9)

    通过JDBC像数据库实现CRUD操作,这里通过一个存储查看人员的案例来了解java是如何通过JDBC实现与数据库的连接,三层结构中的模型层(数据访问),控制层(业务逻辑).以及视图层(表示层)又是怎么 ...

  6. “程序包com.sun.tools.javac.util不存在” 问题解决

    最近工作中在编译打包项目的时候遇到了如标题所示的问题,报这个错误的类是 com.sun.tools.javac.util.Pair.问题很诡异,在Idea可以导入此类,项目启动运行也很正常,但就是在打 ...

  7. css水平垂直居中问题

    水平居中: 行内元素:text-align:center; 块级元素:magin:0 auto; 子元素设置:position:absolute;  left:50%;  transform:tran ...

  8. jQuery进阶第三天(2019 10.12)

    一.原生JS快捷的尺寸(属性)(注意这些属性的结果 不带PX单位) clientWidth/clientHeight  =====> 获得元素content+padding的宽/高: offse ...

  9. vue filters过滤

    <template> <div class="filters"> <h1 v-text="filtersTitle">< ...

  10. 2018-8-10-VisualStudio-修改配色

    title author date CreateTime categories VisualStudio 修改配色 lindexi 2018-08-10 19:16:52 +0800 2018-2-1 ...