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

1746번 - Cow Relays 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 128 MB153714746.535%

문제

For their physical fitness program, N (2 <= N <= 1,000,000) cows have decided to run a relay race using the T (2 <= T <= 100) cow trails throughout the pasture.

Each trail connects two different intersections (1 <= I1_i <= 1,000; 1 <= I2_i <= 1,000), each of which is the termination for at least two trails. The cows know the length_i of each trail (1 <= length_i <= 1,000), the two intersections the trail connects, and they know that no two intersections are directly connected by two different trails. The trails form a structure known mathematically as a graph.

To run the relay, the N cows position themselves at various intersections (some intersections might have more than one cow). They must position themselves properly so that they can hand off the baton cow-by-cow and end up at the proper finishing place.

Write a program to help position the cows. Find the shortest path that connects the starting intersection (S) and the ending intersection (E) and traverses exactly N cow trails.

입력

  • Line 1: Four space-separated integers: N, T, S, and E
  • Lines 2..T+1: Line i+1 describes trail i with three space-separated integers: length_i, I1_i, and I2_i

출력

  • Line 1: A single integer that is the shortest distance from intersection S to intersection E that traverses exactly N cow trails.

제한

예제 입력 1

2 6 6 4
11 4 6
4 4 8
8 4 9
6 6 8
2 6 9
3 8 9

예제 출력 1

10

예제 입력 2

12 6 6 4
11 4 6
4 4 8
8 4 9
6 6 8
2 6 9
3 8 9

예제 출력 2

30

힌트

출처

Olympiad > USA Computing Olympiad > 2007-2008 Season > USACO November 2007 Contest > Gold 2번

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

출처

대학교 대회

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

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