POJ 2395--Out of Hay

POJ 2395 Out of Hay 最小生成树 来源 USACO 2005 March Silver 题目大意 有N(2-2000)个农场,M(1-10000)条通路连通各个农场,长度不超109,要求遍历全部的农场,且每走1单位长度就要消耗一单位水,每到一个农场可以把自己的水充满,求最小的水箱容量。 样例输入 3 3 1 2 23 2 3 1000 1 3 43 样例输出 43 阅读详情

题目:

Description

The cows have run out of hay, a horrible event that must be remedied immediately. Bessie intends to visit the other farms to survey their hay situation. There are N (2 <= N <= 2,000) farms (numbered 1..N); Bessie starts at Farm 1. She'll traverse some or all of the M (1 <= M <= 10,000) two-way roads whose length does not exceed 1,000,000,000 that connect the farms. Some farms may be multiply connected with different length roads. All farms are connected one way or another to Farm 1.

Bessie is trying to decide how large a waterskin she will need. She knows that she needs one ounce of water for each unit of length of a road. Since she can get more water at each farm, she's only concerned about the length of the longest road. Of course, she plans her route between farms such that she minimizes the amount of water she must carry.

Help Bessie know the largest amount of water she will ever have to carry: what is the length of longest road she'll have to travel between any two farms, presuming she chooses routes that minimize that number? This means, of course, that she might backtrack over a road in order to minimize the length of the longest road she'll have to traverse.

Input

* Line 1: Two space-separated integers, N and M.

* Lines 2..1+M: Line i+1 contains three space-separated integers, A_i, B_i, and L_i, describing a road from A_i to B_i of length L_i.

Output

* Line 1: A single integer that is the length of the longest road required to be traversed.

Sample Input

3 3
1 2 23
2 3 1000
1 3 43

Sample Output

43

Hint

OUTPUT DETAILS:

In order to reach farm 2, Bessie travels along a road of length 23. To reach farm 3, Bessie travels along a road of length 43. With capacity 43, she can travel along these roads provided that she refills her tank to maximum capacity before she starts down a road.

题意:求最小生成树中的最大值。


实现:

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

const int MAX = 20005;
int n, m;

int p[MAX];

int _find(int x) {
    return p[x] = (p[x] == x ? x : _find(p[x]));
}

struct node {
    int u, v, e;
    bool friend operator < (node n1, node n2) {
        return n1.e > n2.e;
    }
};

int main() {
    while(scanf("%d%d", &n, &m) != EOF) {
        for (int i = 1; i <= n; i++) {
            p[i] = i;
        }
        priority_queue <node> q;
        int u, v, value;
        for (int i = 0; i < m; i++) {
            scanf("%d%d%d", &u, &v, &value);
            node head;
            head.u = u;
            head.v = v;
            head.e = value;
            q.push(head);
        }

        int ans = -1;

        while (!q.empty()) {
            node tt = q.top();
            q.pop();
            int x, y;
            x = _find(tt.u);
            y = _find(tt.v);
            if (x != y) {
                p[y] = x;
                if (ans < tt.e)
                    ans = tt.e;
            }
        }
        printf("%d\n", ans);
     }

    return 0;
}


使用 Python 和蒙特卡罗计算未来股价走势以及历史波动率和隐含波动率 蒙特卡罗模拟等工具使投资者能够洞察一系列潜在的未来。这远离了单纯的猜测,迈向了明智的、数据驱动的决策。 阅读详情

相关推荐

RK3588开发板RKNPU2环境部署实战:更新rknn_server与librknnrt.so详解

本文详细介绍了在RK3588开发板上更新rknn_server与librknnrt.so核心组件的完整实战流程。通过adb工具推送文件、设置权限并执行同步操作,确保RKNPU2环境部署成功,从而解决推理速度慢或初始化失败等问题,提升AI模型运行效率与稳定性。

weixin_29194817的博客 341

POJ 2395 Out of Hay(最小瓶颈生成树)

POJ 2395 Out of Hay(最小瓶颈生成树) http://poj.org/problem?id=2395 题意:        有N个农场,它们是连通的,现在你要从1号农场找到路走到其他所有农场去.但是有个要求就是你必须使得你将要走的单段路的最大长度最小.也就是说 任意两个农场之间的路如果被你选中要走的话,那么这种单段路的最大值必须尽量小. 分析:        其实就是要

code 1621

Tushare Pro的安装使用——“抱歉,您没有访问该接口的权限,权限的具体详情访问:https://tushare.pro/document/1?doc_id=108”问题

最近做毕设关于量化交易的, 因此一直使用tushare作数据源,但是过程中到一些问题,因此这里写篇文章,供大家一起交流下。 Tushare简介 Tushare是一个免费、开源的python财经数据接口包。拥有如股票、基金、期货等行情数据,公司财务、基金经理等基本面数据,以及债券、外汇、行业、大数据、区块链。Tushare返回的绝大部分的数据格式都是pandas DataFrame类型,因此非常方便...

sinat_40875078的博客 1万+

poj 2395 Out of Hay

poj2395 Out of Hay 这里是求最短路径中的最大边,确实刚开始看。。有点迷,但是跟一般的最小生成树题目没有太大差别,就是在求最小生成树的时候每一次相加边的时候都把较大的那个留下来,就可以得到最短路径上的最大边 #include <iostream> #include <algorithm> #include <cstdio> using names...

CUCUC1的博客 258

CyberChef本地搭建

CyberChef本地搭建

2301_80241182的博客 6077

UE5 StateTree实战:用分层状态机重构你的AI行为逻辑(附蓝图配置避坑点)

本文详细介绍了UE5中StateTree分层状态机的实战应用,帮助开发者重构AI行为逻辑。通过核心概念解析、迁移策略、高级技巧和避坑指南,展示了StateTree在灵活性、可维护性和并行处理方面的优势,特别适合复杂AI行为的开发与优化。

weixin_42558257的博客 249

POJ 2395 Out of Hay [Prim]

POJ&amp;amp;amp;nbsp;2395&amp;amp;amp;nbsp;Out&amp;amp;amp;nbsp;of&amp;amp;amp;nbsp;Hay\text{POJ 2395 Out of Hay}POJ&amp;amp;amp;nbsp;2395&amp;amp;amp;nbsp;Out&amp;amp;amp;nbsp;of&amp;amp;amp;nbsp;Hay 题意简述 给定一个图,求出图中MSTMST

The blog of '_Wallace_'' 217

【论文笔记】Beyond Low-frequency Information in Graph Convolutional Networks

文章目录1. Abstract2. Introduction低频和高频信号作用FAGCN怎么设计3. An Experimental Investigation4. Model4.1 filter定义4.2 Aggregation4.3 Problems of signal combination4.4 Spatial vision of FAGCN4.5 系数αijG\alpha_{i j}^{G}αijG​4.6 模型整体框架FAGCN的表达能力实验 本文发表在AAAI-21上 论文地址:https:

Running Snail 5602

POJ2395 Out of Hay 【Dijkstra】

Out of Hay Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11610   Accepted: 4535 Description The cows have run out of hay, a horrible event that must be r

长风的专栏 1000

一文讲透 SAP VDM 命名里的前缀与后缀:看懂 I_、C_、A_,把 CDS 视图栈搭得又稳又好用

SAP S/4HANA 的 CDS 视图命名规范解析 摘要:本文详细解析 SAP S/4HANA 中 CDS 视图的 VDM 命名规范。通过前缀(如 I_、C_、R_)区分视图层级,后缀标记附加角色,结合 @VDM.viewType 注解形成完整语义体系。I_作为稳定接口层,C_面向特定场景裁剪,R_限定应用域内复用,A_提供远程 API 接口。命名规范使团队能快速识别视图用途、依赖关系和扩展边界,确保模型长期可维护性。文章结合制造业物料主数据、Fiori 应用等实际案例,说明如何通过规范命名构建清晰的视图

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 220

Easy3D&CGAL文章目录汇总

Easy3D&CGAL文章目录汇总

dayuhaitang1的博客 2863

最小生成树(Prim/Kruskal)POJ 2395-Out of Hay

最小生成树(Prim/Kruskal)POJ 2395-Out of Hay 题目链接: Out of Hay 题目基础:最小生成树 最小生成树-Prim(普里姆)算法 最小生成树-Kruskal(克鲁斯卡尔)算法 思路: 题目大意: 一个人从自己的农场出发,要访问N个农场,一共有M条路径(两个农场之间可能存在多条不等长路径),每个农场有水源,在路上需要消耗...

[SZU_Crayon] 371

【从零开始入门unity游戏开发之——C#篇37】进程、线程、C# 中实现多线程有多种方案和async/await异步编程

进程、线程、C# 中实现多线程有多种方案和async/await异步编程

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 1469

POJ 2395 Out of Hay

 Out of Hay Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11030   Accepted: 4320 Description The cows have run out of hay, a horrible event that must be r

Kimi_R_17 802

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

Out of Hay(poj2395)(并查集)

Out of Hay Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11580   Accepted: 4515 Description The cows have run out of hay, a horrible event that must be rem

My Castle 1447

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

Out of Hay(POJ-2395)

Problem Description The cows have run out of hay, a horrible event that must be remedied immediately. Bessie intends to visit the other farms to survey their hay situation. There are N (2 <= N &l...

Alex_McAvoy的博客 700

poj2395 Out of Hay

题意就是给你一张无向连通图,试问对于图上所有点对(u,v)从u到v的所有路径中边权最大值的最小值的最大值。 定义f(u,v)表示从u到v所有路径中边权最大值的最小值,对所有点对取其最大。 实际上就是求图G的最小生成树的最大边权。 考虑kruskal算法流程,每次选取边权最小的且不产生圈的边加入mst。 至算法结束,图恰好连通,并且选取的边权都是最小的。 对于那些产生回路的边加入到mst中...

weixin_34279184的博客 170

POJ 2395 Out of Hay

Out of Hay Time Limit: 1000MS Memory Limit: 65536K Description The cows have run out of hay, a horrible event that must be remedied immediately. Bessie intends to visit the other farms to survey thei...

忘梦心的博客 278

POJ2395-Out of Hay

最小生成树的又一变形题,寻找最小生成树中的最大权值边。 #include #include using namespace std; const int maxn = 2005; const int maxm = 10005; int par[maxn]; int rk[maxn]; void init(int n) { for (int i = 0; i < n; i++)

Collider 412

POJ2395 Out of Hay【Kruskal】

题目大意:1号农场的草被牛吃完了,Bessie必须从其他农场运草回来,总共有N个农场,Bessie要 去其他所有的农场运草回来,他想要使总路程最短并且路线能连接所有的农场。必须要考虑到路上 带的水袋大小。因为水袋大小和路线中距离最长的两个农场之间的路有关,现在Bessie想要求出满 足要求的路线中两个农场之间最长的路距离是多少。 思路:满足要求的路线其实就是最小生成树,路线中两个农场之间最长的路距离就是最小生成树上 最长的边。这样用Kruskal求最小生成树的时候,用Max求出最小生成树上最长的边。

程序员充电站(itcharge) 2050

POJ2395 Out of Hay

Time Limit:1000MS Memory Limit:65536K Total Submissions:15608 Accepted:6108 Description The cows have run out of hay, a horrible event that must be remedied ...

dezhen7015的博客 135

poj2395 Out of Hay —— kruskal

Out of Hay Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19121 Accepted: 7522 - Description The cows have run out of hay, a horrible event that must be remedied ...

zhaohaibo的博客 398

poj-2395 Out of Hay

The cows have run out of hay, a horrible event that must be remedied immediately. Bessie intends to visit the other farms to survey their hay situation. There are N (2 <= N <= 2,000) farms (numbered 1

ML-M的博客 306
上一篇: POJ 1861--Network
下一篇: HDU 2647--Reward
不如烂笔头
博客等级 码龄13年 8粉丝 39原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值