1682: [Usaco2005 Mar]Out of Hay 干草危机
1682: [Usaco2005 Mar]Out of Hay 干草危机
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 391 Solved: 258
[Submit][Status]
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
1 2 23
2 3 1000
1 3 43
Sample Output
由1到达2,需要经过长度23的道路;回到1再到3,通过长度43的道路.最长道路为43
HINT
Source
题解:既然题目说了所有点均与点1联通(phile:废话,那不就是联通无向图啊),那么显(读xian2,我们数学老师口头禅)然这个问题成了最小生成树,然后只要求出最小生成树最大边的值就Accept啦。。
var
i,j,k,l,m,n:longint;
c:array[..] of longint;
a:array[..,..] of longint;
procedure swap(var x,y:longint);
var z:longint;
begin
z:=x;x:=y;y:=z;
end;
procedure sort(l,r:longint);
var i,j,x,y:longint;
begin
i:=l;j:=r;
x:=a[(l+r) div ,];
repeat
while a[i,]<x do inc(i);
while a[j,]>x do dec(j);
if i<=j then
begin
swap(a[i,],a[j,]);
swap(a[i,],a[j,]);
swap(a[i,],a[j,]);
inc(i);dec(j);
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
function getfat(x:longint):longint;
begin
while x<>c[x] do x:=c[x];
getfat:=x;
end;
function tog(x,y:longint):boolean;
begin
exit(getfat(x)=getfat(y));
end;
procedure merge(x,y:longint);
begin
c[getfat(x)]:=getfat(y);
end;
begin
readln(n,m);
for i:= to m do
readln(a[i,],a[i,],a[i,]);
for i:= to n do c[i]:=i;
sort(,m);
j:=;
l:=;
for i:= to n- do
begin
while tog(a[j,],a[j,]) do inc(j);
if a[j,]>l then l:=a[j,];
merge(a[j,],a[j,]);
end;
writeln(l);
end.
1682: [Usaco2005 Mar]Out of Hay 干草危机的更多相关文章
- 【BZOJ】1682: [Usaco2005 Mar]Out of Hay 干草危机(kruskal)
http://www.lydsy.com/JudgeOnline/problem.php?id=1682 最小生成树裸题.. #include <cstdio> #include < ...
- BZOJ 1682: [Usaco2005 Mar]Out of Hay 干草危机
Description 牛们干草要用完了!贝茜打算去勘查灾情. 有N(2≤N≤2000)个农场,M(≤M≤10000)条双向道路连接着它们,长度不超过10^9.每一个农场均与农场1连通.贝茜要走遍每一 ...
- bzoj 1682: [Usaco2005 Mar]Out of Hay 干草危机【并查集+二分】
二分答案,把边权小于mid的边的两端点都并起来,看最后是否只剩一个联通块 #include<iostream> #include<cstdio> using namespace ...
- bzoj1682[Usaco2005 Mar]Out of Hay 干草危机*
bzoj1682[Usaco2005 Mar]Out of Hay 干草危机 题意: 给个图,每个节点都和1联通,奶牛要从1到每个节点(可以走回头路),希望经过的最长边最短. 题解: 求最小生成树即可 ...
- [Usaco2005 Mar]Out of Hay 干草危机
题目描述 Bessie 计划调查N (2 <= N <= 2,000)个农场的干草情况,它从1号农场出发.农场之间总共有M (1 <= M <= 10,000)条双向道路,所有 ...
- 【最小生成树】BZOJ1682[Usaco2005 Mar]-Out of Hay 干草危机
...最小生成树裸题,9月最后一天刷水刷水. #include<iostream> #include<cstdio> #include<algorithm> usi ...
- BZOJ 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机
题目 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机 Time Limit: 5 Sec Memory Limit: 64 MB Desc ...
- 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机
1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: ...
- BZOJ1680: [Usaco2005 Mar]Yogurt factory
1680: [Usaco2005 Mar]Yogurt factory Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 106 Solved: 74[Su ...
随机推荐
- localToLocal坐标变换
localToLocal坐标变换 $(function() { init(); }); // localtoLocal var stage, arm, handler; function init(e ...
- Pomelo的Router
在pomelo中,对服务器的扩充非常简单,只需要修改一下配置文件config/servers.json,多添几台服务器配置就行了,如果我们的connector和chat都具有多台服务器,因此需要考虑对 ...
- 车大棒浅谈for循环+canvas实现黑客帝国矩形阵
背景: 一日在网上闲逛的之时,突然看到一个利用JQ插件实现canvas实现的电影黑客帝国的小Demo.觉得创意不错,就下载下来研究一下. 网上浏览jQuery的写法 $(document).ready ...
- Apriori算法原理总结
Apriori算法是常用的用于挖掘出数据关联规则的算法,它用来找出数据值中频繁出现的数据集合,找出这些集合的模式有助于我们做一些决策.比如在常见的超市购物数据集,或者电商的网购数据集中,如果我们找到了 ...
- There is no getter for property named 'userId' in 'class java.lang.String'
[ERROR] 2017-01-18 04:37:06:231 cn.dataenergy.common.CenterHandlerExceptionResolver (CenterHandlerEx ...
- 如何从本地把项目上传到github&&如何把github项目通过clone复制下来
一.第一步---注册一个Github账号 首先要在GitHub上创建一个帐号,可以去官方网站注册一个账号. 二.git安装 下载地址:http://msysgit.github.io/ 二.第二步-- ...
- Backdoor CTF 2013: 电子取证 250
0x00 题目 h4x0r厌烦了你对他的城堡的所有攻击,所以他决定报复攻击你,他给你发来一封带有图片的邮件作为警告,希望你能找出他的警告消息:-) 消息的MD5值就是flag. 0x01 解题法1 给 ...
- RabbitMQ安装和使用(和Spring集成)
一.安装Rabbit MQ Rabbit MQ 是建立在强大的Erlang OTP平台上,因此安装Rabbit MQ的前提是安装Erlang.通过下面两个连接下载安装3.2.3 版本: 下载并安装 E ...
- SQL Server-聚焦SNAPSHOT基于行版本隔离级别详解(三十)
前言 上一篇SQL Server详细讲解了隔离级别,但是对基于行版本中的SNAPSHOT隔离级别仍未完全理解,本节再详细讲解下,若有疑义或不同见解请在评论中提出,一起探讨. SNAPSHOT行版本隔离 ...
- 《响应式Web设计—HTML5和CSS3实战》 学习记录
作者:Ben Frain 学习时间 2016/5/12 第一章 设计入门 *视口调试工具 IE:Microsoft Internet Explorer Develop Toolbar Safa ...