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.
 
题意:要求从1到N找到T条路径,路径上的边不能重复,要求最大的边最小,问那条边是多少
思路:二分答案。每次二分一个长度,然后求最大流看能不能走出T条边。至于建图,每两条可直达的边之间建一条双向边,容量为1,最大流就是能走出的路径数。
PS:搞个有容量上限的最大流,直接清空流就不用每次都建图了。据说DINIC在单位流量的图复杂度为O(ElogV)。
 
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std; const int MAXN = 210;
const int MAXE = 40010 * 2;
const int INF = 0x7f7f7f7f; struct Dinic {
int n, m, st, ed, ecnt, maxlen;
int head[MAXN];
int cur[MAXN], d[MAXN];
int to[MAXE], next[MAXE], flow[MAXE], cap[MAXE], len[MAXE]; void init(int ss, int tt) {
st = ss; ed = tt;
ecnt = 2;
memset(head, 0, sizeof(head));
} void add_edge(int u, int v, int c, int l) {
len[ecnt] = l; to[ecnt] = v; cap[ecnt] = c; flow[ecnt] = 0; next[ecnt] = head[u]; head[u] = ecnt++;
len[ecnt] = l; to[ecnt] = u; cap[ecnt] = c; flow[ecnt] = 0; next[ecnt] = head[v]; head[v] = ecnt++;
} bool bfs() {
memset(d, 0, sizeof(d));
queue<int> que; que.push(st);
d[st] = 1;
while(!que.empty()) {
int u = que.front(); que.pop();
for(int p = head[u]; p; p = next[p]) {
if(len[p] > maxlen) continue;
int v = to[p];
if(!d[v] && cap[p] > flow[p]) {
d[v] = d[u] + 1;
que.push(v);
if(v == ed) return true;
}
}
}
return d[ed];
} int dfs(int u, int a) {
if(u == ed || a == 0) return a;
int outflow = 0, f;
for(int &p = cur[u]; p; p = next[p]) {
if(len[p] > maxlen) continue;
int v = to[p];
if(d[u] + 1 == d[v] && (f = dfs(v, min(a, cap[p] - flow[p]))) > 0) {
flow[p] += f;
flow[p ^ 1] -= f;
outflow += f;
a -= f;
if(a == 0) break;
}
}
return outflow;
} int Maxflow(int mlen) {
int ans = 0; maxlen = mlen;
while(bfs()) {
for(int i = 0; i <= ed; ++i) cur[i] = head[i];
ans += dfs(st, INF);
}
return ans;
}
} G; int main() {
int n, m, T, left = 0, right = 0;
scanf("%d%d%d", &n, &m, &T);
G.init(1, n);
for(int i = 0; i < m; ++i) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
G.add_edge(a, b, 1, c);
if(right < c) right = c;
}
while(left < right) {
memset(G.flow, 0, sizeof(G.flow));
int mid = (left + right) >> 1;
if(G.Maxflow(mid) < T) left = mid + 1;
else right = mid;
}
printf("%d\n", right);
}

  

 

POJ 2455 Secret Milking Machine(最大流+二分)的更多相关文章

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

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

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

    题目大意: 给出一张无向图,找出T条从1..N的路径,互不重复,求走过的所有边中的最大值最小是多少. 算法讨论: 首先最大值最小就提醒我们用二分,每次二分一个最大值,然后重新构图,把那些边权符合要求的 ...

  3. poj 2455 Secret Milking Machine 二分+最大流 sap

    题目:p条路,连接n个节点,现在需要从节点1到节点n,不重复走过一条路且走t次,最小化这t次中连接两个节点最长的那条路的值. 分析:二分答案,对于<=二分的值的边建边,跑一次最大流即可. #in ...

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

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

  5. POJ 2455 Secret Milking Machine (二分+无向图最大流)

    [题意]n个点的一个无向图,在保证存在T条从1到n的不重复路径(任意一条边都不能重复)的前提下,要使得这t条路上经过的最长路径最短. 之所以把"经过的最长路径最短"划个重点是因为前 ...

  6. POJ 2455 - Secret Milking Machine

    原题地址:http://poj.org/problem?id=2455 题目大意:给出一个N个点的无向图,中间有P条边,要求找出从1到n的T条通路,满足它们之间没有公共边,并使得这些通路中经过的最长的 ...

  7. POJ Secret Milking Machine 【网络流+二分】

    题意:各一个地图,两点之间有若干条路,要在节点1和节点n之间行走t次(就是问1到n的路径数至少为t,每一条路径不能有重复),问所有路径里面最长的部分(这个题目特别强调,不是路径长度和,是路径中相邻两点 ...

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

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

  9. BZOJ 1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机 网络流 + 二分答案

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

随机推荐

  1. 19-3-5Python中列表、元组、以及range

    一.列表: 为什么要学列表? 因为字符串存在缺点: 1)      只能存储少量的数据. 2)      数据类型无论索引.切片 获取的都是字符串类型,类型过于单一,转化成它原来的类型还需要进一步转换 ...

  2. Zabbix——设置阈值和报警

    前提条件: Zabbix 服务器可以正常监控其他设备 Zbbix 已经配置完成了邮件报警 Zabbix server版本为4.0 配置ICMP监测,1分钟如果ping不通,将会发送邮件 找到Templ ...

  3. 通过xshell在linux上安装mysql5.7(终极版)

    通过xshell在linux上安装mysql5.7(终极版) 0)通过xshell连接到远程服务器 1)彻底删除原来安装的mysql 首先查看:rpm -qa|grep -i mysql 删除操作(一 ...

  4. The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.报该错误的一种原因。

    今天发现某个action返回404. HTTP Status 404 – Not Found Type Status Report Message /xxx.action Description Th ...

  5. ubuntu网卡配置及安装ssh服务

    1.ubuntu网卡配置 1.查看网卡名称 ip a 2.进行编辑网卡配置文件 sudo vi /etc/network/interfaces 更改网卡配置文件添加内容修改内容如下:下面的enp0s3 ...

  6. 纯js轮播图练习-1

    偶尔练习,看视频自己学着做个简单的纯JS轮播. 简单的纯js轮播图练习-1. 样子就是上面图片那样,先不管好不好看,主要是学会运用和理解轮播的原理 掌握核心的理论知识和技术的操作,其他的都可以在这个基 ...

  7. java中有关Volatile的几个小题

    1.java中能创建volatile数组吗? 能,java中可以创建volatile数组,不过只是一个指向数组的引用,而不是整个数组,如果改变引用指向的数组,将会受到volatile的保护,但是如果多 ...

  8. 常用数字信号的产生(C实现)-均匀分布&正态分布

    小白博主开始学DSP之路,为了激励自己能坚持下去,写一系列博客来记录下来,也欢迎与大家一起讨论.介于我能力所限,这里学习目标定为,学习一个基础知识,写一个C语言程序实现, 最后会形成一个C的函数库,方 ...

  9. 【blockly教程】Blockly编程案例

    案例一 原码反码和补码  我们把一个数在计算机内被表示的二进制形式称为机器数,该数称为这个机器数的真值.机器数有固定的位数,具体是多少位与机器有关,通常是8位或16位.原码:是指符号位用0或1表示,0 ...

  10. Canvas在移动端设备上模糊出现锯齿边

    在绘制的过程中画布内容的实际大小是根据 canvas 的 width 与 height 属性设置的,而 style 或者CSS设置的width 与 height 只是简单的对画布进行缩放. canva ...