#P3020. [USACO11MAR] Package Delivery S

[USACO11MAR] Package Delivery S

题目描述

Farmer John must deliver a package to Farmer Dan, and is preparing to make his journey. To keep the peace, he gives a tasty treat to every cow that he meets along his way and, of course, FJ is so frugal that he would like to encounter as few cows as possible.

农夫约翰必须送一个包裹给农夫丹,并准备去旅行。为了保持和平,他必须给每一头遇到的奶牛一些吃的,当然,FJ很节俭,他想可能遇到尽可能少的奶牛。

FJ has plotted a map of N (1 <= N <= 50,000) barns, connected by M (1 <= M <= 50,000) bi-directional cow paths, each with C_i (0 <= C_i <= 1,000) cows ambling along it. A cow path connects two distinct barns, A_i and B_i (1 <= A_i <= N; 1 <= B_i <= N; A_i != B_i). Two barns may be directly connected by more than one path. He is currently located at barn 1, and Farmer Dan is located at barn N.

FJ已经绘制了N(1≤N≤50000)个谷仓的地图,通过M条(1 <= M = 50000)双向牛道,每条双向牛道上有c[i](0 <= c[i] <= 1000)奶牛漫步。双向牛道连接两个不同的谷仓,a[i]和b[i](1 <= a[i] <= N;1 < = b[i] <= N;a[i]!= b[i])。两个谷仓可以由一条以上的小路直接连接。他目前在1号谷仓,农夫丹位于N号谷仓。

Consider the following map:

           [2]---
          / |    \
         /1 |     \ 6
        /   |      \
     [1]   0|    --[3]
        \   |   /     \2
        4\  |  /4      [6]
          \ | /       /1
           [4]-----[5] 
                3  

The best path for Farmer John to take is to go from 1 -> 2 -> 4 -> 5 -> 6, because it will cost him 1 + 0 + 3 + 1 = 5 treats.

Given FJ's map, what is the minimal number of treats that he should bring with him, given that he will feed each distinct cow he meets exactly one treat? He does not care about the length of his journey.

输入格式

* Line 1: Two space-separated integers: N and M

* Lines 2..M+1: Three space-separated integers: A_i, B_i, and C_i

输出格式

* Line 1: The minimum number of treats that FJ must bring

6 8 
4 5 3 
2 4 0 
4 1 4 
2 1 1 
5 6 1 
3 6 2 
3 2 6 
3 4 4 
5