bzoj#P1752. [Usaco2005 qua] Til the Cows Come Home
[Usaco2005 qua] Til the Cows Come Home
题目描述
Bessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes her for the morning milking. Bessie needs her beauty sleep, so she wants to get back as quickly as possible.
Farmer John's field has landmarks in it, uniquely numbered . Landmark is the barn; the apple tree grove in which Bessie stands all day is landmark . Cows travel in the field using bidirectional cow-trails of various lengths between the landmarks.
Bessie is not confident of her navigation ability, so she always stays on a trail from its start to its end once she starts it.
Given the trails between the landmarks, determine the minimum distance Bessie must walk to get back to the barn. It is guaranteed that some such route exists.
输入格式
- Line : Two integers: and .
- Lines : Each line describes a trail as three space-separated integers. The first two integers are the landmarks between which the trail travels. The third integer is the length of the trail.
输出格式
- Line : A single integer, the minimum distance that Bessie must travel to get from landmark to landmark .
5 5
1 2 20
2 3 30
3 4 20
4 5 20
1 5 100
90
样例说明
There are five landmarks. Bessie can get home by following trails , , , and .
数据规模与约定
对于 的数据:,, 铁轨长度 。
题目来源
Usaco2005 qua