#P5764. [CQOI2005] 新年好

[CQOI2005] 新年好

Description

There are nn stations in Chongqing City, and mm bidirectional roads connect some of them. Between any two stations, there is at most one road. Starting from any station, you can reach any other station by taking one or more roads, but different paths may take different amounts of time. The time spent on a path equals the sum of the times of all roads on that path.

Jiajia’s home is at station 11. He has five relatives who live at stations a,b,c,d,ea,b,c,d,e. During the Spring Festival, he needs to start from home and visit each relative (in any order) to send them holiday greetings. How should he travel to spend the least total time?

Input Format

The first line contains n,mn,m, the number of stations and the number of roads.

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

The next mm lines each contain three integers x,y,tx,y,t, representing the two stations connected by a road and the time of that road.

Output Format

Output only one line containing an integer TT, the minimum total time. It is guaranteed that T109T\le 10^9.

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
21

Hint

For 40%40\% of the testdata, 1n5001\le n\le 500 and 1m20001\le m\le 2000.

For 100%100\% of the testdata, 1n500001\le n\le 50000, 1m1000001\le m\le 100000, 1a,b,c,d,en1\le a,b,c,d,e\le n, 1x,yn1\le x,y\le n, and 1t100001\le t\le 10000.

Translated by ChatGPT 5