QOJ.ac

QOJ

実行時間制限: 7 s メモリ制限: 1024 MB 満点: 100

#6448. 开辟新径

統計

您的州刚刚购买了一大片未开发的土地,并希望将其改造成一个带有徒步小径的自然公园。这片土地上有 $n$ 个游客可能想要前往的景点,其中 $k$ 个景点非常特殊。州政府希望用徒步小径连接这些景点。现有 $m$ 条候选徒步小径可供选择,每条小径直接连接两个景点,且具有不同的建设成本。选择小径时需要满足一些约束条件。首先,从任意一个景点到其他任何景点必须有且仅有一条徒步路径。其次,必须恰好有 $w$ 条小径直接连接一个特殊景点和一个普通景点。当然,州政府希望最小化建设这些小径的总成本。

输入格式

每个输入包含一个测试用例。请注意,您的程序可能会在不同的输入上运行多次。输入的第一行包含四个整数 $n, m, k$ 和 $w$,其中 $n$ ($2 \le n \le 2 \cdot 10^5$) 是景点数量,$m$ ($1 \le m \le 5 \cdot 10^5$) 是景点之间潜在的直接小径数量,$k$ ($1 \le k < n$) 是特殊景点的数量,$w$ ($1 \le w \le n - 1$) 是州政府希望建设的连接特殊景点与普通景点的小径数量。景点编号为 $1 \dots n$。

接下来的 $k$ 行,每行包含一个整数 $s$ ($1 \le s \le n$),表示特殊景点。这些值是唯一的,并按升序排列。

接下来的 $m$ 行,每行描述一条州政府可以建设的潜在小径。每行包含三个整数 $a, b$ 和 $c$,表示该小径连接景点 $a$ 和 $b$ ($1 \le a, b \le n, a \neq b$),建设成本为 $c$ ($1 \le c \le 10^5$)。任意两个景点之间不会有多于一条的潜在小径,且从 $a$ 到 $b$ 的小径与从 $b$ 到 $a$ 的小径相同。

输出格式

输出一个整数,表示在满足约束条件的前提下,州政府建设公园小径的最小总成本;如果无法满足条件,则输出 $-1$。

样例

样例输入 1

3 3 1 2
2
1 2 2
1 3 1
2 3 3

样例输出 1

5

样例输入 2

3 1 1 1
2
1 2 2

样例输出 2

-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.