Foody Uncle Mike
View as PDFUncle Mike goes on various food adventures from town to town. Today he finds himself in food-topia, a land containing only restaurants, which are connected by bi-directional roads.
Uncle Mike wishes to visit a restaurant , but there are just so many temptations along the
way - how could he resist the aroma of food waffing through the air! Everytime Mike passes by a
restaurant, he must simply try it! But at the same time, he does not want to arrive
at his destination too late and it is closed. Help uncle Mike find his way to restaurant
as
quickly as possible!
Input
The first line contains ,
- the number of restaurants, and the number of direct paths
between two restaurants.
The next line contains ,
that is the restaurant uncle Mike first started at, and the
restaurant uncle Mike wants to get to.
The third line contains numbers that is the eating time
at each restaurant.
The next lines contains two restaurants
and the time
taken to go between them.
Output
Print a single number, that is the minimum amount of time needed for uncle Mike to arrive at
restaurant .
Constraints
- It is guaranteed that there is at most one direct path between any two restaurants.
- It is guaranteed that there always exist a valid path between
and
.
Example 1
Input
5 4
1 5
1 2 3 4 5
1 2 1
1 3 2
4 2 3
5 4 7
Output
18
Explanation
The restaurants and their connecting roads are depicted in the diagram below.

Mike starts at restaurant , and wants to travel to restaurant
. In order to do so, he must
spend
units of time travelling on the road, and
units of time eating at
restaurants
,
and
along the way.
Example 2
Input
6 9
3 4
2 17 8 6 9 3
1 2 6
1 3 10
1 4 21
2 3 5
2 5 7
3 6 11
4 5 31
4 6 4
5 6 28
Output
26
Explanation
The restaurants and their connecting roads are depicted in the diagram below.

Mike starts at restaurant , and wants to travel to restaurant
. In order to do so, he can
travel through vertex
. This takes
units of time on the road, and
units of time eating
at restaurants
and
.
Comments