QOJ.ac

QOJ

Time Limit: 7 s Memory Limit: 1024 MB Total points: 100

#6448. 開闢新路徑

Statistics

你所在嘅州啱啱買咗一大片未經開發嘅土地,希望將佢改建成一個有遠足徑嘅自然公園。呢片土地有 $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$ 到 $n$。

之後 $k$ 行,每行有一個整數 $s$($1 \le s \le n$),表示一個特別景點。呢啲數值互不相同,並且按遞增次序排列。

之後 $m$ 行,每行描述一條州政府可以開闢嘅候選遠足徑。每行有三個整數 $a$、$b$ 同 $c$,表示條遠足徑會連接景點 $a$ 同 $b$($1 \le a,b \le n$,$a \ne 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.