Problem C
Hittast
Languages
en
is

Álfur and Benedikt are in love and want nothing more than to spend their time together. Sadly, they don’t live close to each other. Álfur lives in Helsinki but Benedikt lives in Buenos Aires. So they can’t meet up whenever they want. They decided to coordinate where and when to meet up next.
A date has been decided, but not a location. They have no preference for location, as long as they are together. But Álfur is a university student, so his budget is limited. They’ve asked you to find the cheapest solution for them.
Benedikt has written down all possible meeting locations and found the cheapest lodging option at each location. He also found various different travel options between the locations. Álfur and Benedikt have different credit cards, so they may not get the same prices. Can you use this information to find the cheapest option for these love birds.
Input
The first line of the input contains two integers
The follow
All prices in the input are at least
You may assume that all locations are reachable from all other locations.
Output
Print a single integer, the cheapest cost for Álfur and Benedikt to meet.
Scoring
Group |
Points |
Constraints |
1 |
10 |
The only locations are Helsinki and Buenos Aires:
|
2 |
20 |
There is no travel cost, only lodging cost |
3 |
30 |
|
4 |
40 |
No further constraints |
Sample Input 1 | Sample Output 1 |
---|---|
2 1 10 1 1 2 50 60 |
51 |
Sample Input 2 | Sample Output 2 |
---|---|
4 6 1000 400 450 900 3 4 0 0 1 2 0 0 1 4 0 0 3 1 0 0 2 3 0 0 4 2 0 0 |
400 |
Sample Input 3 | Sample Output 3 |
---|---|
4 6 0 4 5 0 3 4 1 2 1 2 2 3 1 4 9 9 3 1 3 3 2 3 2 1 4 2 5 3 |
4 |