프로그램 명: usa_apple
제한시간: 1 초

[문제 요약] 사과 2 개를 그래프 상의 길을 따라 두 곳으로 배달하려고 한다. 가장 빠른 길을 찾는 것이 문제이다.

입력으로

9 7 5 1 4 // 9 개의 길 .7 개의 정점 . 5 번 정점에서 출발하여 두 정점 1 , 4 번 으로 배달(방문)
5 1 7
6 7 2
4 7 2
5 6 1
5 2 4
4 3 2
1 2 3
3 2 2
2 6 3
모든 정점은 연결되어 있고 , 양 방향 길이고 길의 합은 2,000,000,000 을 넘지 않는다.
                3        2       2
           [1]-----[2]------[3]-----[4]
             \     / \              /
             7\   /4  \3           /2
               \ /     \          /
               [5]-----[6]------[7]
                    1       2
5 번 정점에서 1 번 , 4 번 정점을 방문해야 한다면 아래의 길이 최적이고 비용의 합은 12
      5 -> 6-> 7 -> 4* -> 3 -> 2 -> 1*

Bessie has two crisp red apples to deliver to two of her friends in the herd. Of course, she travels the C (1 <= C <= 200,000) cowpaths which are arranged as the usual graph which connects P (1 <= P <= 100,000) pastures conveniently numbered from 1..P: no cowpath leads from a pasture to itself, cowpaths are bidirectional, each cowpath has an associated distance, and, best of all, it is always possible to get from any pasture to any other pasture. Each cowpath connects two differing pastures P1_i (1 <= P1_i <= P) and P2_i (1 <= P2_i <= P) with a distance between them of D_i. The sum of all the distances D_i does not exceed 2,000,000,000.

What is the minimum total distance Bessie must travel to deliver both apples by starting at pasture PB (1 <= PB <= P) and visiting pastures PA1 (1 <= PA1 <= P) and PA2 (1 <= PA2 <= P) in any order. All three of these pastures are distinct, of course.

Consider this map of bracketed pasture numbers and cowpaths with distances:

                3        2       2
           [1]-----[2]------[3]-----[4]
             \     / \              /
             7\   /4  \3           /2
               \ /     \          /
               [5]-----[6]------[7]
                    1       2
If Bessie starts at pasture [5] and delivers apples to pastures [1] and [4], her best path is:
      5 -> 6-> 7 -> 4* -> 3 -> 2 -> 1*

with a total distance of 12.

입력

출력

* Line 1: The shortest distance Bessie must travel to deliver both apples

입출력 예

입력

9 7 5 1 4
5 1 7
6 7 2
4 7 2
5 6 1
5 2 4
4 3 2
1 2 3
3 2 2
2 6 3


출력

12
출처:usaco 2010 DEC silver

[질/답] [제출 현황] [푼 후(0)]
[ 채 점 ] [홈으로]  [뒤 로]