QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 256 MB Total points: 100

#6523. 逃生计划

Statistics

BaoBao 是最著名的怪物猎人之一,他在被怪物统治的 Heltion 市中心醒来。由于记不清发生了什么,BaoBao 决定尽快逃离这座可怕的城市。尽管没有携带任何武器,但他幸运地在右口袋里发现了一张地图,上面包含了一些可能帮助他找到出路的宝贵信息。

根据地图,Heltion 市由 $n$ 个地点和 $m$ 条无向路径组成。BaoBao 从地点 1 出发,必须前往城市的 $k$ 个出口中的任意一个以逃离,其中第 $i$ 个出口位于地点 $e_i$。

然而,由于城市里到处都是怪物,BaoBao 的逃生之路并不容易!对于所有 $1 \le i \le n$,第 $i$ 个地点附近徘徊着 $d_i$ 只怪物,因此当 BaoBao 到达该地点后,连接该地点的路径中最多会有 $d_i$ 条被怪物封锁,导致 BaoBao 无法通过。当 BaoBao 离开第 $i$ 个地点时,怪物会回到它们的巢穴,被封锁的路径也会畅通。当然,如果 BaoBao 回到该地点,最多又会有 $d_i$ 条路径被怪物封锁。每次被封锁的路径可能不同。

由于 BaoBao 不知道哪些路径会被封锁,请帮他计算在最坏情况下他逃离城市所需的最短时间。

输入格式

输入包含多组测试数据。第一行包含一个整数 $T$(约 100),表示测试数据的组数。对于每组测试数据:

第一行包含三个整数 $n, m$ 和 $k$ ($1 \le n \le 10^5, 1 \le m \le 10^6, 1 \le k \le n$),分别表示地点数量、无向路径数量和城市出口数量。

第二行包含 $k$ 个不同的整数 $e_1, e_2, \dots, e_k$ ($1 \le e_i \le n$),表示 Heltion 市的 $k$ 个出口。

第三行包含 $n$ 个整数 $d_1, d_2, \dots, d_n$ ($0 \le d_i \le m$),其中 $d_i$ 表示第 $i$ 个地点的怪物数量。

接下来的 $m$ 行中,第 $i$ 行包含三个整数 $x_i, y_i$ 和 $w_i$ ($1 \le x_i, y_i \le n, x_i \neq y_i, 1 \le w_i \le 10^4$),表示连接地点 $x_i$ 和 $y_i$ 的一条长度为 $w_i$ 的无向边。

保证所有测试数据的 $n$ 之和不超过 $10^6$,所有测试数据的 $m$ 之和不超过 $3 \times 10^6$。

输出格式

对于每组数据,输出一行包含一个整数。如果 BaoBao 在最坏情况下能够到达某个出口,输出最短可能的时间花费;否则,如果 BaoBao 在最坏情况下无法到达任何出口,则输出 “-1”(不含引号)。

样例

样例输入 1

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

样例输出 1

4
-1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.