Out of Hay

Time Limit: 1000MS Memory Limit: 65536K

Total Submissions: 13094 Accepted: 5078

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.

Source

USACO 2005 March Silver

求最小生成树的最大边,Kruskal

#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#define LL long long
using namespace std; const int INF = 0x3f3f3f3f; const int MAX = 11000; int n,m; int pre[3000]; typedef struct node
{
int x;
int y;
int dis;
}K;
K Edge[MAX];
void init()
{
for(int i=1;i<=n;i++)
{
pre[i]=i;
}
}
bool cmp(node a,node b)
{
return a.dis<b.dis;
} int Find(int x)
{
return x==pre[x]?x:pre[x]=Find(pre[x]);
} int Kruskal()
{
int num=0,Max=0;
for(int i=0;i<m;i++)
{
int a=Find(Edge[i].x);
int b=Find(Edge[i].y);
if(a!=b)
{
num++;
pre[a]=b;
if(Max<Edge[i].dis)
{
Max=Edge[i].dis;
}
}
if(num==n-1)
{
break;
}
}
return Max;
}
int main()
{
while(~scanf("%d %d",&n,&m))
{
init();
for(int i=0;i<m;i++)
{
scanf("%d %d %d",&Edge[i].x,&Edge[i].y,&Edge[i].dis);
}
sort(Edge,Edge+m,cmp);
printf("%d\n",Kruskal());
}
return 0;
}

Out of Hay的更多相关文章

  1. 洛谷P1547 Out of Hay

    题目背景 奶牛爱干草 题目描述 Bessie 计划调查N (2 <= N <= 2,000)个农场的干草情况,它从1号农场出发.农场之间总共有M (1 <= M <= 10,0 ...

  2. 瓶颈生成树与最小生成树 POJ 2395 Out of Hay

    百度百科:瓶颈生成树 瓶颈生成树 :无向图G的一颗瓶颈生成树是这样的一颗生成树,它最大的边权值在G的所有生成树中是最小的.瓶颈生成树的值为T中最大权值边的权. 无向图的最小生成树一定是瓶颈生成树,但瓶 ...

  3. 洛谷P2925 [USACO08DEC]干草出售Hay For Sale

    题目描述 Farmer John suffered a terrible loss when giant Australian cockroaches ate the entirety of his ...

  4. [BZOJ1618][Usaco2008 Nov]Buying Hay 购买干草

    [BZOJ1618][Usaco2008 Nov]Buying Hay 购买干草 试题描述 约翰的干草库存已经告罄,他打算为奶牛们采购H(1≤H≤50000)磅干草. 他知道N(1≤N≤100)个干草 ...

  5. Codeforces Round #346 (Div. 2) F. Polycarp and Hay 并查集

    题目链接: 题目 F. Polycarp and Hay time limit per test: 4 seconds memory limit per test: 512 megabytes inp ...

  6. Hay Points

    Hay Points TimeLimit: 1 Second   MemoryLimit: 32 Megabyte Totalsubmit: 1022   Accepted: 602 Descript ...

  7. BZOJ1606: [Usaco2008 Dec]Hay For Sale 购买干草

    1606: [Usaco2008 Dec]Hay For Sale 购买干草 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 612  Solved: 46 ...

  8. POJ 2395 Out of Hay(最小生成树中的最大长度)

    POJ 2395 Out of Hay 本题是要求最小生成树中的最大长度, 无向边,初始化es结构体时要加倍,别忘了init(n)并查集的初始化,同时要单独标记使用过的边数, 判断ans==n-1时, ...

  9. poj 2395 Out of Hay(最小生成树,水)

    Description The cows have run <= N <= ,) farms (numbered ..N); Bessie starts at Farm . She'll ...

随机推荐

  1. 寻找第K大的数

    在一堆数据中查找到第k个大的值. 名称是:设计一组N个数,确定其中第k个最大值,这是一个选择问题,解决这个问题的方法很多. 所谓“第(前)k大数问题”指的是在长度为n(n>=k)的乱序数组中S找 ...

  2. PostgreSQL Monitor pg_activity

    PostgreSQL Monitor pg_activity Command line tool for PostgreSQL server activity monitoring. https:// ...

  3. HttpContext.Current 的缺陷

    了解ASP.NET的开发人员都知道它有个非常强大的对象 HttpContext,而且为了方便,ASP.NET还为它提供了一个静态属性HttpContext.Current来访问它,今天的博客打算就从H ...

  4. java中的Robot

    项目中最近遇到了一个棘手问题,无法用WebDriver去操作win弹出窗口,经过多番查找,发现了Robot这个奇葩东东,Robot可以模拟鼠标和键盘操作, robot可以实现本地系统输入空包括win弹 ...

  5. 判断java中两个对象是否相等

    java中的基本数据类型判断是否相等,直接使用"=="就行了,相等返回true,否则,返回false. 但是java中的引用类型的对象比较变态,假设有两个引用对象obj1,obj2 ...

  6. CCF真题之日期计算

    201509-2 日期计算 问题描述 给定一个年份y和一个整数d,问这一年的第d天是几月几日? 注意闰年的2月有29天.满足下面条件之一的是闰年: 1) 年份是4的整数倍,而且不是100的整数倍: 2 ...

  7. System Hold, Fix Manager before resetting counters

    程序pending http://www.askmaclean.com/archives/2011/11 http://blog.itpub.net/35489/viewspace-717132/ 1 ...

  8. zw版_Halcon-delphi系列教程_卫星航拍精确打击目标自动识别

    <zw版·Halcon-delphi系列原创教程> 卫星航拍精确打击目标自动识别 这几天,俄罗斯空军在叙利亚大显神威,美军有意见了,说俄罗斯是狂轰滥炸,不是精确打击.      不过,战斗 ...

  9. selenium 右键另存为操作

    from selenium import webdriverfrom selenium.webdriver.common.action_chains import ActionChainsbrowse ...

  10. Delphi内嵌汇编语言BASM精要(转帖)

    1 BASM概念简要  汇编语句由指令和零至三个表达式构成.表达式由常数(立即数).寄存器和标识符构成.例如: movsb        // 单指令语句 jmp @Here    // 一个表达式: ...