poj 2455 Secret Milking Machine

限时加码!20+主流AI编程工具免费用 购周边加赠Coding Plan Lite,Claude Code、Cursor等即刻畅享,学习进阶更高效! 阅读详情

(http://www.elijahqi.win/2017/12/25/poj2455-secret-milking-machine/)
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
USACO 2005 February Gold
二分一下 我路径上最大的值是多少 然后每次只把<=这个权值的边建出来 然后跑权值为1的最大流 看这样的路径一共有几条 输出即可
注意这题有个坑点 就是路径条数>=t就可以 所以判定的时候要注意点


#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 220
#define inf 0x3f3f3f3f
using namespace std;
inline char gc(){
    static char now[1<<16],*S,*T;
    if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
    return *S++;
}
inline int read(){
    int x=0;char ch=gc();
    while(ch<'0'||ch>'9') ch=gc();
    while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=gc();}
    return x; 
}
struct node{
    int x,y,z,next;
}data1[88000],data[88000];
inline bool cmp(node a,node b){return a.z<b.z;}
int n,p,t,num=1,h[N],level[N];
inline void insert1(int x,int y,int z){
    data[++num].y=y;data[num].z=z;data[num].next=h[x];h[x]=num;
    data[++num].y=x;data[num].z=z;data[num].next=h[y];h[y]=num;
}
inline bool bfs(){
    memset(level,0,sizeof(level));queue<int>q;level[1]=1;q.push(1);
    while(!q.empty()){
        int x=q.front();q.pop();
        for (int i=h[x];i;i=data[i].next){
            int y=data[i].y,z=data[i].z;
            if (level[y]||!z) continue;level[y]=level[x]+1;q.push(y);if (y==n) return 1;
        }
    }return 0;
}
inline int dfs(int x,int s){
    if (x==n) return s;int ss=s;
    for (int i=h[x];i;i=data[i].next){
        int y=data[i].y,z=data[i].z;
        if (level[x]+1==level[y]&&z){
            int xx=dfs(y,min(s,z));if (!xx) level[y]=0;
            s-=xx;data[i].z-=xx;data[i^1].z+=xx;if (!s) return ss; 
        }
    }return ss-s;
}
inline bool check(int mid){
    memset(h,0,sizeof(h));num=1;
    for (int i=1;i<=p;++i){
        if (data1[i].z>mid) break;
        insert1(data1[i].x,data1[i].y,1);
    }int ans=0;while(bfs()) ans+=dfs(1,inf);if (ans>=t) return 1;else return 0;
}
int main(){
    freopen("poj2455.in","r",stdin);
    n=read();p=read();t=read();int max1=0;
    for (int i=1;i<=p;++i) data1[i].x=read(),data1[i].y=read(),data1[i].z=read(),max1=max(max1,data1[i].z);
    sort(data1+1,data1+p+1,cmp);int l=1,r=max1;
    while(l<=r){
        int mid=l+r>>1;
        if (check(mid)) r=mid-1;else l=mid+1;
    }
    printf("%d",l);
    return 0;
}
QGIS-空间分析-核密度分析 本文在QGIS软件中使用核密度估计法分析全球历年的地震数据,旨在分析出地震频发且严重的区域,为地震防控提供参考依据。全球历年地震数据来源于网络,仅用于技术学习探索。通过核密度分析,可以观察到南美、美国西部海岸线和太平洋北部区域在全球地震分布状态中是最为集中和强烈的。 阅读详情

相关推荐

AIGC在游戏行业的应用:革新游戏开发与体验

AIGC(人工智能生成内容)技术正在深刻改变游戏行业,从开发到体验全面革新。在游戏开发中,AIGC可用于自动生成关卡、角色和剧情,提升开发效率;在资源制作中,通过AI生成场景、角色模型等,降低成本。

1589

洛谷 P3389 【模板】高斯消元法 × 洛谷 P2455 [SDOI2006]线性方程组

一、传送门 https://www.luogu.com.cn/problem/P3389 https://www.luogu.com.cn/problem/P2455 二、代码 日……两道题合起来搞了我十几个小时,最后把我气得从别人的 AC 代码开始再一句一句改成适配自己模板的同义的语句。 有些细节还是不太懂,暂时先把模板放上来。以后有时间再出详解。 ———————————————————————...

COFACTOR 267

TS808效果器制作教程

TS808效果器制作教程 可以在立创商城购买到大部分的电阻电容和IC,音频接口,踩钉,电位器和电源接口可以去某宝看看都买得到的。链接https//pan.baidu.com/s/1QId1eIE3fJ2u5NLBSISvGA。安装过程过于繁琐,把所有元器件按照图纸焊接完成就可以调试了,祝你们成功!这是TS808经典效果器制作过程的记录。IC是JRC4558。...

qq_18948149的博客 3340

中国源码网站大全 以及ALEXA排名

网址                   ALEXA排名www.chinaz.com  141www.cncode.com 20,083www.downcode.com 8367www.my503.com  57,646 www.cncodez.com 755,718 www.2okok.com 8,196www.jianjie8.com  64,320www.zg010.com 245,098w...

weixin_34122548的博客 1万+

在linux服务器上装svn版本管理,自动部署代码到项目

在linux服务器上装svn版本管理,自动部署代码到项目 http://bbs.aliyun.com/read/9715.html?spm=5176.7114037.1996646101.1.W3zw3X&pos=1 http://v5sheji.com/archives/setupsvnonlinux.html 1.安装svn服务器端 yum instal...

anlei2455的博客 256

Poj 2455 Secret Milking Machine【二分+最大流】

Secret Milking Machine Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11570   Accepted: 3354 Description Farmer John is constructing a new

mengxiang000000 869

Secret Milking Machine POJ - 2455

题意: 给定一张无向图,有n个节点p条边, 要求在图中从1到n找到t条路径,并且使这t条路径中的最长边最小, 输出这个最小的最长边 /*题意:给定一张无向图,有n个节点p条边, 要求在图中从1到n找到t条路径,并且使这t条路径中的最长边最小, 输出这个最小的最长边 */ #include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;...

空白 281

解题报告 之 POJ2455 Secret Milking Machine

解题报告 之 POJ2455 Secret Milking Machine 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 hi

JUST CODE 675

poj 2455 Secret Milking Machine 二分+dinic求最大流

poj 2455 Secret Milking Machine 二分 + dinic求最大流 //poj 2455 Secret Milking Machine //二分 + 最大流 //题意: //输入第一行3个数为结点数,边数,路径数 //接下来为每条边的信息 //要求找出对应路径数中每条边都尽量小,输出这些路径中的边最长边为多少 //每条边只能用一次 //思路: ...

weixin_30338461的博客 111

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

POJ 2455 Secret Milking Machine 题目链接 题意:一个无向图,要求有T条不重复道路可以从1走到t,问道路中最大边的最小值可以是多少 思路:二分+最大流,二分长度,连起边,注意是无向图,所以反向边是有容量的,然后源点和1连容量t,n和汇点连容量是t 代码: #include #include #include #include us

Remilia's 1043

POJ2455 Secret Milking Machine

Secret Milking Machine Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12324   Accepted: 3589 Description Farmer John is constructing a new milking machine

Jelly_acm的博客 382

POJ 2455 Secret Milking Machine 网络流初步 Dinic

POJ 2455 Secret Milking Machine网络流初步,Dinic模板终于碰到Edmond-Karp过不了的题了。。40000条边,O(nm^2)果断T。。 传送门:POJ 题意又是农场主约翰(咋最近都是这SB农场主。。为了更好调$教他的“奶%牛”?) 他的农场有N个点(1~N),之间有P条双向的路。他想从点1走到点N,走T次。要求不能重复的走一条路两遍。 求满足条件的方案

P.H.S 311

POJ 2455 Secret Milking Machine

POJ_2455 每条路只走一次可以通过网络流来保证,而对于让最长的边最小可以通过二分枚举来搞定。 #include<stdio.h> #include<string.h> #include<algorithm> #define MAXD 210 #define MAXM 80010 #define INF 0x3f3f3f3f in...

weixin_30342827的博客 73

poj2455Secret Milking Machine

http://poj.org/problem?id=2455(题目链接) 题意   给出一张n个点,p条边的无向图,需要从1号节点走到n号节点一共T次,每条边只能经过1次,问T次经过的最大的边最小是多少。 Solution   很显然,二分答案,然后建图跑最大流即可。 细节   双向边? 代码 // poj2455 #include<algorithm> #i...

weixin_30558305的博客 113

Secret Milking Machine POJ - 2455

点击打开链接 二分最大边 记为lim 不超过lim的边容量记为1 否则记为0 再抽象一个源点 从源点到1的容量为题目所给的t 然后以此建图 看是否满流 感觉网络流的抽象建图很关键 这道题看了别人的建图才会的... 符合条件就是1 即存在 反之就是0 即不存在 这样就把一个记录路径长度的图转化为记录路径是否可行的图 每增广一次图中就少一条路 长知识了!   #include &lt;st...

sunyutian1998的博客 307

POJ 2455 Secret Milking Machine 最大流建模

题目链接http://poj.org/problem?id=2455题意某人为了隐藏他的挤奶机,可能是为了不让别人跟踪,他决定从1~n,然后走密道回到1,再从1到n,走t次,且每条路径不同,每次尽量走路径最短的路,问他在t次走的过程中,两个路标之间的最大距离。思路二分枚举最大边权。如果两点的边权小于等于枚举的量,之间建立一条容量为1的边,若有重边满足条件,容量加1,最后从1点跑最大流,判断最大流是否

chen_minghui的博客 319

POJ-2455-Secret Milking Machine

这个题TLE了我N次,想不到Dinic会被卡,后来看了下别人写的代码,发现DFS中有不同之处,改了下结果就奇迹班的200多ms过了,看来以后改进下自己的写法了 这个题不太难吧,图建立不难,可能只是卡时间吧,题目大意是说求1到n点的t条不同路径的最大值的最小值 最大最小值问题用二分法做 代码: #include #include #include using namespace std; c

z309241990的专栏 1009
上一篇: poj2516 Minimum Cost
下一篇: bzoj1497 [NOI2006]最大获利
elijahqi
博客等级 码龄9年 55粉丝 1280原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值