logo AlgoBeat OnlineJudge
登录 注册

#101752. [BZOJ 1752] [Usaco2005 qua]Til the Cows Come Home

内存限制:64 MiB 时间限制:5000 ms 标准输入输出
题目类型:传统 评测方式:文本比较
上传者: 匿名

题目描述

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 .

样例

样例输入 #1

5 5
1 2 20
2 3 30
3 4 20
4 5 20
1 5 100

样例输出 #1

90

样例说明

There are five landmarks. Bessie can get home by following trails , , , and .

数据范围与提示

对于 的数据: 铁轨长度

Usaco2005 qua