1682: [Usaco2005 mar]out of hay hay crisis time limit:5 Sec Memory limit:64 MB
submit:391 solved:258
[Submit] [Status] Description
The cows has run out of hay, a horrible event, which must be remedied immediately. Bessie intends to visit the other farms to survey their hay situation. There is 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 <= in) two-way roads whose length does not exceed 1,000,000,000 tha T connect the farms. Some Farms May is multiply connected with different length roads. All farms is connected one or another to Farm 1. Bessie is trying to decide how large a waterskin she'll need. She knows that she needs one ounce of the 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'll ever has to carry:what are the length of the longest road she ' ll have the T O Travel betweenMS, presuming she chooses routes that minimize? This means, of course, that she-might backtrack over a road in order to minimize the length of the longest road she ' ll hav E to traverse.
The cows are running out of hay! Bessie is going to explore the disaster. There are N (2≤n≤2000) farms, and M (≤m≤10000) Two-way roads connect them, not exceeding 109 in length. Each farm is 1 connected to the farm. Bessie went to every farm. She takes a unit of water every time she walks a long way. Walking from one farm to another, she is going to take a quantity of water equal to the length of the road. Please help her to determine the minimum tank capacity. That is to say, identify a scheme that makes the longest path through which all farms pass the smallest length and, if necessary, she can backtrack. 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.
Line 1th Enter two integers n and m; next m line, enter three integers per line, indicating the end point and length of a road. Output
* Line 1: A single integer, that's the length of the longest road required to be traversed.
Outputs an integer that represents the minimum value of the longest road on the route. Sample Input3 3
1 2 23
2 3 1000
1 3 43
Sample Output43
From 1 to 2, it takes 23 of the way through the length of the road; back to 1 to 3, through the length of 43 of the road. The longest road isHINT Source
Silver
The problem: Since the topic said all points are connected with point 1 (phile: Nonsense, that is not unicom map AH), then display (read xian2, our math teacher Mantra) This issue has become the smallest spanning tree, and then just find the minimum spanning tree maximum edge value on the accept.
1 var2 I,j,k,l,m,n:longint;3C:Array[0.. the] ofLongint;4A:Array[0..15000,1..3] ofLongint;5 procedureSwapvarx,y:longint);6 varZ:longint;7 begin8z:=x;x:=y;y:=Z;9 End;Ten proceduresort (l,r:longint); One varI,j,x,y:longint; A begin -i:=l;j:=R; -x:=a[(L+r)Div 2,3]; the Repeat - whileA[i,3]<x DoInc (i); - whileA[j,3]>x DoDec (j); - ifI<=j Then + begin -Swap (A[i,1],a[j,1]); +Swap (A[i,2],a[j,2]); ASwap (A[i,3],a[j,3]); at Inc (I);d EC (j); - End; - untilI>J; - ifL<j Thensort (l,j); - ifI<r Thensort (i,r); - End; in functionGetfat (x:longint): Longint; - begin to whileX<>C[X] Dox:=C[x]; +getfat:=x; - End; the functiontog (X,y:longint): boolean; * begin $Exit (Getfat (x) =Getfat (y));Panax Notoginseng End; - proceduremerge (x,y:longint); the begin +C[getfat (x)]:=Getfat (y); A End; the begin + readln (n,m); - fori:=1 toM Do $READLN (A[i,1],a[i,2],a[i,3]); $ fori:=1 toN Doc[i]:=i; -Sort1, m); -j:=1; thel:=0; - fori:=1 toN-1 DoWuyi begin the whileTog (A[j,1],a[j,2]) DoInc (J); - ifA[j,3]>l ThenL:=a[j,3]; WuMerge (A[j,1],a[j,2]); - End; About Writeln (l); $ End. -
1682: [Usaco2005 mar]out of hay in the haystack crisis