Happy New Year


Submit solution

Points: 1
Time limit: 2.0s
Memory limit: 256M

Problem type
Allowed languages
Python

Problem Description

There are n stations and m bidirectional roads connecting some of these stations in Chongqing city.

Each pair of stations is connected by at most one road. Starting from any station, one can reach other stations through one or more roads, but different paths may require different amounts of time.

The time spent on a path equals the sum of the times required for all roads on the path.

Jiajia`s home is at station 1, and he has five relatives living at stations a, b, c, d, and e respectively.

During the New Year, he needs to start from his home, visit each relative (in any order), and send them holiday blessings.

What is the route that requires the least total time?

Input Format
The first line contains two integers n, m, representing the number of stations and the number of roads.

The second line contains five integers a, b, c, d, e, representing the station numbers where the five relatives live.

The next m lines each contain three integers x, y, t, indicating the two stations connected by a road and the time required to travel it.

Output Format
Output a single integer T, representing the minimum total time required.

Data Range
1 ≤ n ≤ 50000
1 ≤ m ≤ 105
1 < a, b, c, d, en
1 ≤ x, yn
1 ≤ t ≤ 100

Input Sample:

6 6
2 3 4 5 6
1 2 8
2 3 3
3 4 4
4 5 5
5 6 2
1 6 7

Output Sample:

21

Comments

There are no comments at the moment.