Luogu P1339 [usaco 09oct] Heat Wave (Shortest circuit), p1339usaco 09oct
Description
The good folks in Texas are having a heatwave this summer. their Texas Longhorn cows make for good eating but are not so adept at creating creamy delicious dairy products. farmer John is leading the charge to deliver plenty of ice cold nutritious milk to Texas so the Texans will not suffer the heat too much.
FJ has studied the routes that can be used to move milk from Wisconsin to Texas. these routes have a total of T (1 <= T <= 2,500) towns conveniently numbered 1 .. T along the way (including the starting and ending towns ). each town (could not the source and destination towns) is connected to at least two other towns by bidirectional roads that have some cost of traversal (owing to gasoline consumption, tolls, etc .). consider this map of seven towns; town 5 is
Source of the milk and town 4 is its destination (bracketed integers represent costs to traverse the route ):
[1]----1---[3]- / \ [3]---6---[4]---3--[3]--4 / / /| 5 --[3]-- --[2]- | \ / / | [5]---7---[2]--2---[3]--- | / [1]------
Traversing 5-6-3-4 requires spending 3 (5-> 6) + 4 (6-> 3) + 3 (3-> 4) = 10 total expenses.
Given a map of all the C (1 <= C <= 6,200) connections (described as two endpoints R1i and R2i (1 <= R1i <= T; 1 <= R2i <= T) and costs (1 <= Ci <= 1,000 ), find the smallest total expense to traverse from the starting town Ts (1 <= Ts <= T) to the destination town Te (1 <= Te <= T ).
Simple Texas citizens are experiencing a huge heat wave this summer !!! They have a good meal, but they are not very good at producing Cream-rich milk products. Farmer John was at this time with the joys and sorrows of the world, taking on the task of transporting a large amount of nutritious, cold milk to Texas, to relieve Texas people from suffering from the heat.
FJ has studied how milk can be shipped from Wisconsin to Texas. These routes include the starting point and the ending point first passing through T (1 <= T <= 2,500) towns, which are conveniently marked as 1 to T. Each town except the start and end areas is connected by two-way roads to at least two other towns. There is a pass-through fee for each road (including the fuel fee, the toll, and so on ).
Given a map, it contains C (1 <= C <= 6,200) roads that are directly connected to two towns. Start Point Rs of each road, end point Re (1 <= Rs <= T; 1 <= Re <= T), and cost (1 <= Ci <= 1,000). Calculate the minimum total cost of the town Te (1 <= Ts <= T) from the start point to the end point.
Input/Output Format
Input Format:
Line 1: Four integers separated by spaces: T, C, Ts, Te
Lines 2nd to C + 1: I + 1 Describe the I-th Road. There are three integers separated by spaces: Rs, Re, and Ci
Output Format:
A separate integer represents the minimum total cost from Ts to Te. There must be at least one path to data assurance.
Input and Output sample input sample #1: Copy
7 11 5 42 4 21 4 37 2 23 4 35 7 57 3 36 1 16 3 42 4 35 6 37 2 1
Output example #1: Copy
7
Description
[Example]
5-> 6-> 1-> 4 (3 + 1 + 3)
The bare Shortest Path updates the dijstra board.