luogu#P4943. 密室

密室

Background

NOIP 2018 original mock problem T2.

Difficulty similar to NOIP Day 1 T2 or Day 2 T2.

The background is adapted from the novel Harry Potter and the Chamber of Secrets.

Problem Description

The Chamber of Secrets has been opened.

Harry and Ron enter the chamber. They find that the chamber consists of nn rooms, numbered 1,2,,n1,2,\ldots,n. There are mm passages between the rooms. For any two different rooms, there is at most one passage connecting them. Passing through the ii-th passage takes CiC_i time.

At the beginning, both Harry and Ron are in room 11. Their goals are to rescue Ginny and find the diary, but Ginny and the diary may be in two different rooms. To uncover the truth as quickly as possible, they decide to reach the two target rooms in the least time. However, some rooms can only be entered by someone who can talk to snakes, meaning only Harry can enter them.

Now, Harry tells you the structure of the chamber. Please compute the shortest time for them to reach the two target rooms.

Input Format

The first line contains n,m,kn,m,k, meaning there are nn rooms, mm passages, and kk rooms that only Harry can enter.

The second line contains kk numbers, giving the indices of the rooms that only Harry can enter. (If k=0k=0, this line is omitted.)

The next mm lines each contain 33 numbers a,b,ca,b,c, meaning there is a passage between room aa and room bb with time cost cc.

The last line contains two numbers x,yx,y, indicating the two rooms that Harry and Ron need to go to.

Output Format

Output one number in a single line, representing the minimum time to reach the two target rooms.

6 8 1
5
1 2 3
2 3 2
1 3 4
3 4 1
4 6 5
5 6 2
1 6 6
1 5 3
4 6
5
10 13 3
3 4 10
1 2 1
2 3 2
3 4 3
4 5 4
5 6 5
6 7 10
7 8 5
8 9 10
9 10 3
10 1 2
1 9 6
3 8 10
4 6 3
6 8
16

Hint

Explanation of the samples:

Sample 1:

Harry: 1561 \to 5 \to 6, time cost is 55.

Ron: 1341 \to 3 \to 4, time cost is 55.

So the minimum time is 55.

Sample 2:

Figure 1

As shown, orange marks the target rooms, and green marks rooms that only Harry can pass through.

Harry: 123461 \to 2 \to 3 \to 4 \to 6, time cost is 99.

Ron: 1981 \to 9 \to 8, time cost is 1616.

So the minimum time is 1616.

Constraints:

For 10%10\% of the testdata: n5n\leq 5.

For 30%30\% of the testdata: n20n\leq 20.

For 50%50\% of the testdata: n1000n\leq 1000.

For 70%70\% of the testdata: n10000n\leq 10000.

For 100%100\% of the testdata: n50000n\leq 50000; a,b,kna,b,k\leq n; c1000c\leq 1000; m100000m\leq 100000. It is guaranteed that Ron can be in room 11.

Special note:

For 30%30\% of the testdata: k=0k=0.

Translated by ChatGPT 5