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 NN landmarks in it, uniquely numbered 1N1\cdots N. Landmark 11 is the barn; the apple tree grove in which Bessie stands all day is landmark NN. Cows travel in the field using TT 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 11: Two integers: TT and NN.
  • Lines 2T+12\sim T+1: 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 11: A single integer, the minimum distance that Bessie must travel to get from landmark NN to landmark 11.
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 44, 33, 22, and 11.

数据规模与约定

对于 100%100\% 的数据:2N1032 \leq N \leq 10^31T21031 \leq T \leq 2*10^311\leq 铁轨长度 100\leq 100

题目来源

Usaco2005 qua