[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 \le N \le 50000)$ 个谷仓的地图,通过 $M(1 \le M \le 50000)$ 条双向牛道,每条双向牛道上有 $c[i](0 \le c[i] \le 1000)$ 奶牛漫步。双向牛道连接两个不同的谷仓,$a[i]$ 和 $b[i](1 \le a[i] \le N,1 \le b[i] \le N, a[i] \neq b[i])$。两个谷仓可以由一条以上的小路直接连接。他目前在 $1$ 号谷仓,农夫丹位于 $N$ 号谷仓。 Consider the following map: ```cpp [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

输入输出样例

输入样例 #1

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 

输出样例 #1

5