1682: [Usaco2005 Mar]Out of Hay 干草危机

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 626  Solved: 436
[Submit][Status][Discuss]

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.

    牛们干草要用完了!贝茜打算去勘查灾情.
    有N(2≤N≤2000)个农场,M(≤M≤10000)条双向道路连接着它们,长度不超过109.每一个农场均与农场1连通.贝茜要走遍每一个农场.她每走一单位长的路,就要消耗一单位的水.从一个农场走到另一个农场,她就要带上数量上等于路长的水.请帮她确定最小的水箱容量.也就是说,确定某一种方案,使走遍所有农场通过的最长道路的长度最小,必要时她可以走回头路.

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.

    第1行输入两个整数N和M;接下来M行,每行输入三个整数,表示一条道路的起点终点和长度.

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

中文题面又少说一句话:贝茜一开始在点1上

不过这都不重要了因为没什么用

一眼Kruskal,答案就是最小生成树中最长的那条边的长度

#include<stdio.h>
#include<algorithm>
using namespace std;
typedef struct Road
{int x, y;int len;bool operator < (const Road &b) const{if(len<b.len)return 1;return 0;}
}Road;
Road s[10005];
int ufs[2005];
int Find(int x)
{if(ufs[x]==0)return x;return ufs[x] = Find(ufs[x]);
}
int main(void)
{int n, m, i, sum, t1, t2;scanf("%d%d", &n, &m);for(i=1;i<=m;i++)scanf("%d%d%d", &s[i].x, &s[i].y, &s[i].len);sort(s+1, s+m+1);sum = n;for(i=1;i<=m;i++){t1 = Find(s[i].x);t2 = Find(s[i].y);if(t1!=t2){ufs[t1] = t2;sum--;}if(sum==1)break;}printf("%d\n", s[i].len);return 0;
}

bzoj 1682: [Usaco2005 Mar]Out of Hay 干草危机(最小生成树)相关推荐

  1. 1682: [Usaco2005 Mar]Out of Hay 干草危机

    1682: [Usaco2005 Mar]Out of Hay 干草危机 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 391  Solved: 258 ...

  2. bzoj 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机

    1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: ...

  3. BZOJ 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机 bfs

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1615 1615: [Usaco2008 Mar]The Loathesome Hay Bale ...

  4. BZOJ 1738: [Usaco2005 mar]Ombrophobic Bovines 发抖的牛( floyd + 二分答案 + 最大流 )

    一道水题WA了这么多次真是.... 统考终于完 ( 挂 ) 了...可以好好写题了... 先floyd跑出各个点的最短路 , 然后二分答案 m , 再建图. 每个 farm 拆成一个 cow 点和一个 ...

  5. bzoj 1681: [Usaco2005 Mar]Checking an Alibi 不在场的证明(BFS)

    1681: [Usaco2005 Mar]Checking an Alibi 不在场的证明 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 389  So ...

  6. BZOJ 1615 [Usaco2008 Mar] The Loathesome Hay Baler 麻烦的干草打包机(BFS)

    [问题描述] FJ新买的干草打包机的内部结构大概算世界上最混乱的了,它不象普通的机器一样有明确的内部传动装置,而是N个齿轮互相作用,每个齿轮都可能驱动着多个齿轮. FJ记录了对于每个齿轮i,记录了它的 ...

  7. 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机

    1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: ...

  8. [BZOJ1615][Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机

    1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: ...

  9. 【BZOJ】1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机(模拟+bfs)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1615 这种题..... #include <cstdio> #include <c ...

最新文章

  1. 通过 React Hooks 声明式地使用 setInterval
  2. 传统IDC转型有了新思路 Zstack除了混合云还有托管云
  3. 设计模式之间的关联关系和对比
  4. 大连印象_2010暑期实训有感【一】
  5. Spring Cloud Config - RSA简介以及使用RSA加密配置文件
  6. 抖音短视频内容理解和推荐算法
  7. 全图化引擎(AI·OS)中的编译技术
  8. java物理架构_Java应用架构读书笔记(1):物理设计与逻辑设计
  9. 创建虚拟文件系统设备文件节点_使用proc_create实例分析
  10. sqlserver 查找某个字符在字符串中第N次出现的位置
  11. 在内核中分配物理地址连续的大内存.
  12. 北斗文档下载工具-百度文库文档每天免费2次机会下载
  13. Dell 电脑插入耳机无声音或重启后有声音
  14. 实用的搜索引擎资源大搜罗
  15. WordPress 网站基于REST API 开发“微信小程序”实战
  16. Java实现 蓝桥杯 算法提高 日期计算
  17. [XMAN2018排位赛]AutoKey
  18. Android Studio使用AIDL技术进行SDK开发
  19. 微商加粉方法,微商加粉,究竟难在哪?
  20. Ubuntu 安装Chrome(DEB 出现问题使用)

热门文章

  1. 零基础学python全彩版-零基础轻松学Python:青少年趣味编程(全彩版)
  2. python能做什么工作-学python后能找什么工作?Python是什么?
  3. 学了python能干啥举例-1 行Python代码能干哪些事,这 13个你知道吗?
  4. 产品开发管理方法工具流程 pdf_HR必备薪酬和绩效管理方法论、工具、案例
  5. FFmpeg源代码简单分析:av_write_frame()
  6. FFMPEG结构体分析:AVStream
  7. java怎么这么难学6_Java难吗?
  8. 火狐 mysql插件_火狐firebug和firepath插件安装方法(最新)
  9. java reactor模式例子_JAVA BIO,NIO,Reactor模式总结
  10. jdbc增删改查有哪些步骤_JDBC打造通用增删改方法