CGIVING
Problem
Farmer John is distributing chocolates at the barn for Valentine's day, and of his bulls have a special cow in mind to receive a chocolate gift.
Each of the bulls and cows is grazing alone in one of the farm's pastures conveniently numbered and connected by bidirectional cowpaths of various lengths. Some pastures might be directly connected by more than one cowpath. Cowpath connects pastures and and has length .
Bull resides in pasture and wishes to give a chocolate to the cow in pasture .
Help the bulls find the shortest path from their current pasture to the barn (which is located at pasture ) and then onward to the pasture where their special cow is grazing. The barn connects, one way or another (potentially via other cowpaths and pastures) to every pasture.
As an example, consider a farm with pastures, paths, and bulls (in pastures , , and ) who wish to bestow chocolates on their love-objects:
*1 <-- Bull wants chocolates for pasture 1 cow
[4]--3--[5] <-- [5] is the pasture ID
/ |
/ |
4 2 <-- 2 is the cowpath length
/ | between [3] and [4]
[1]--1--[3]*6
/ /
9 3 2
/ /
[6] [2]*4
The Bull in pasture can travel distance (two different ways) to get to the barn then travel distance to pastures [3] and [4] to gift his chocolate. That's altogether.
The Bull in pasture can travel to pasture (distance ), then pastures and (total: ) to bestow his chocolate offer.
The Bull in pasture can travel distance to pasture and then take his chocolate more to pasture , a total distance of .
Input
In the first line of input, there will be three space separated integers , , and .
In the next to lines, line describes cowpath with three space-separated integers: , , and .
In the next to lines, line contains two space separated integers: and .
Output
The output will consist of the lines to , where line should contain a single integer, the smallest distance that the bull in pasture must travel to get chocolates from the barn and then award them to the cow of his dreams in pasture .
Example of Input - Output Files:
STDIN (ttime.in)
6 7 3
1 2 3
5 4 3
3 1 1
6 1 9
3 4 2
1 4 4
3 2 2
2 4
5 1
3 6
STDOUT (ttime.out)
6
6
10
Constraints
- .
- .
- .
- Maximum execution time: sec.
- Available memory : MB.
Comments