#P9650. [SNCPC2019] Escape Plan

    ID: 9014 Type: RemoteJudge 4000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 4 Uploaded By: Tags>2019O2优化最短路陕西XCPC

[SNCPC2019] Escape Plan

题目描述

BaoBao, one of the most famous monster hunters, wakes up in the middle of Heltion City dominated by monsters. Having troubles remembering what has happened, BaoBao decides to escape from this horrible city as soon as possible. Despite arming no weapon, he luckily puts his hand on a map in his right pocket, which contains valuable information that can possibly help him find a way out.

According to the map, Heltion City is composed of nn spots connected by mm undirected paths. Starting from spot 11, BaoBao must head towards any of the kk exits of the city to escape, where the ii-th of them is located at spot eie_i.

However, it's not an easy task for BaoBao to escape since monsters are everywhere in the city! For all 1in1 \le i \le n, did_i monsters are wandering near the ii-th spot, so right after BaoBao arrives at that spot, at most did_i paths connecting the spot will be blocked by monsters and are unable for BaoBao to pass. When BaoBao leaves the ii-th spot, the monsters will go back to their nests and the blocked paths are clear. Of course, if BaoBao comes back to the spot, at most did_i paths will be again blocked by the monsters. The paths blocked each time may differ.

As BaoBao doesn't know which paths will be blocked, please help him calculate the shortest time he can escape from the city in the worst case.

输入格式

There are multiple test cases. The first line of the input contains an integer TT (about 100100), indicating the number of test cases. For each test case:

The first line contains three integers nn, mm and kk (1n1051 \le n \le 10^5, 1m1061 \le m \le 10^6, 1kn1 \le k \le n), indicating the number of spots, the number of undirected paths and the number of exits of the city.

The second line contains kk distinct integers e1,e2,,eke_1, e_2, \dots, e_k (1ein1 \le e_i \le n), indicating kk exits of Heltion City.

The third line contains nn integers d1,d2,,dnd_1, d_2, \dots, d_n (0dim0 \le d_i \le m), where did_i indicates the number of monsters at the ii-th spot.

For the following mm lines, the ii-th line contains three integers xix_i, yiy_i and wiw_i (1xi,yin1 \le x_i,y_i \le n, xiyix_i \neq y_i, 1wi1041 \le w_i \le 10^4), indicating an undirected edge of length wiw_i connecting spot xix_i and yiy_i.

It's guaranteed that the total sum of nn will not exceed 10610^6 and the total sum of mm will not exceed 3×1063 \times 10^6.

输出格式

For each case output one line containing one integer. If BaoBao can get to some exit in the worst case, output the shortest possible time cost; Otherwise if BaoBao cannot get to any exit in the worst case, output -1 instead.

2
3 4 1
3
1 1 1
1 2 1
1 2 2
2 3 1
2 3 2
3 2 2
2 3
2 0 0
1 2 1
1 3 1

4
-1