Logo
(追記) (追記ここまで)

27075번 - Secret Milk Pipes 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB198844.444%

문제

Farmer John wants to connect his water distribution system cheaply, but he doesn't want his rival, Farmer Snidely, to be able to predict the actual routes he chooses. FJ knows that this kind of problem usually asks for the cheapest way to connect water pipes, so he decides to avoid that and use the second cheapest way instead.

Given a list of all the bidirectional pipes that might connect a set of W (3 ≤ W ≤ 2000) water stations (any one of which can be made into a well) along with the costs for no more than P (P ≤ 20,000) pipes, find the second cheapest way to distribute water. No pipe connects a station to itself; no two pipes connect the same pair of stations.

It is guaranteed that there is only one cheapest way to distribute the water and that there are at least two ways to distribute the water. All costs are positive integers that fit into a signed 16-bit entity. A water station is identified by its ID number, which is an integer in the range 1..W.

입력

  • Line 1: Two space-separated integers, W and P
  • Lines 2..P+1: Each line describes a single pipe and contains three space-separated integers: a water station that is one endpoint of a pipe, a water station that is the other endpoint of a pipe, and the cost of that pipe.

출력

A single line with a single integer that is the second lowest cost to construct a water distribution system.

제한

예제 입력 1

5 7
1 2 3
2 3 4
1 4 7
2 4 11
2 5 9
5 4 5
3 5 8

예제 출력 1

20

힌트

출처

Olympiad > USA Computing Olympiad > 2001-2002 Season > USACO US Open 2002 Contest > Green 2번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /