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,\ldots,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.