QOJ.ac

QOJ

حد الوقت: 1.0 s حد الذاكرة: 512 MB مجموع النقاط: 100 قابلة للهجوم ✓

#7077. 羊村

الإحصائيات

有一个古老的国家叫“羊村”,它包含 $n$ 个编号从 $1$ 到 $n$ 的城市以及 $m$ 条双向道路,每条道路连接两个不同的城市。

在羊村中,城市通过道路相连。也就是说,你总能通过某些道路找到从一个城市到另一个城市的路径。此外,这里的每条道路最多属于一个简单环,其中简单环是指一组形成循环路径 $u_1 \to u_2 \to \dots \to u_m \to u_1$ ($m \ge 1$) 且不经过重复城市的道路集合。注意,循环路径 $a \to b \to c \to a$、$b \to c \to a \to b$ 和 $a \to c \to b \to a$ 对应同一个环。

羊村里住着 $k$ 只羊,也有 $k$ 只潜伏的狼。一旦所有的羊都睡着了,由狼王带领的潜伏狼群将对它们静止的猎物发动闪电战。悄悄穿过一条道路是需要消耗能量的。为了节能,狼王希望为每只狼分配一只不同的羊,使得捕捉羊所消耗的总能量尽可能小。

作为一名既是狼又是杰出的战略家,现在轮到你来做出决定,以满足狼王的要求。

输入格式

第一行包含三个整数 $n, m$ 和 $k$ ($2 \le n \le 10^5, n - 1 \le m \le 2n - 2, 1 \le k \le 10^5$),分别表示羊村的城市数量、城市间的道路数量以及羊(或狼)的总数。

第二行包含 $k$ 个整数,其中第 $i$ 个数 $a_i$ ($1 \le a_i \le n$) 表示第 $i$ 只狼潜伏在编号为 $a_i$ 的城市中。

第三行包含 $k$ 个整数,其中第 $i$ 个数 $b_i$ ($1 \le b_i \le n$) 表示第 $i$ 只羊在编号为 $b_i$ 的城市中睡觉。一些羊和狼可能住在同一个城市。

接下来的 $m$ 行,每行包含三个整数 $u, v$ 和 $w$ ($1 \le u, v \le n, u \neq v, 1 \le w \le 10^5$),表示一条连接编号为 $u$ 和 $v$ 的城市的双向道路,狼悄悄穿过它需要消耗 $w$ 的能量。任意两个城市之间可能存在多条道路。

输出格式

输出一行一个整数,表示消耗的最小总能量。

样例

样例输入 1

5 8 4
2 2 3 3
4 4 5 5
1 2 1
2 1 1
1 3 1
3 1 1
1 4 1
4 1 1
1 5 1
5 1 1

样例输出 1

8

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#288EditorialOpen题解jiangly2025-12-14 06:52:48View

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.