Parcel Delivery
Time limit1sMemory limit128 MB
Given a weighted undirected graph, find the minimum total edge weight along a path from barn 1 to barn N.
- Level
Easy3 of 10
- Topics
- Shortest path, Graph
- Solved
- No attempts yet
Problem
Farmer Hyunseo has to deliver a parcel to Farmer Chanhong, and he is just about to set off. To pass through peacefully, he must feed tasty fodder to every cow he meets along the way. But Hyunseo is a miser, so he wants to travel while meeting as few cows as possible.
Hyunseo has a map. It shows barns and two-way paths that connect them. The -th path has cows on it and connects two distinct barns and . Two barns may be connected by more than one path. Hyunseo is at barn , and Chanhong is at barn .
Refer to the map below.
[2]---
/ | \
/1 | \ 6
/ | \
[1] 0| --[3]
\ | / \2
4\ | /4 [6]
\ | / /1
[4]-----[5]
3
On this map, the best route Hyunseo can take is , for which the total number of cows he meets is .
Given Hyunseo's map and the amount of fodder he must give whenever he meets cows on a path, find the minimum total fodder he must give while traveling from barn to barn . The travel distance is not taken into account.
Input
The first line contains two integers and , separated by a space.
Each of the next lines contains three integers , , and , meaning that the path connecting barn and barn has cows on it.
Output
Print the minimum total fodder Hyunseo must give while traveling from barn to barn .