QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100

#913. Butterfly Graph

统计

Watching butterflies unable to fly across the ends of the earth, who has the right not to understand?

An undirected graph together with two vertex sets $L$ and $R$ is called a butterfly graph if and only if the following conditions are satisfied:

  • $L \cup R$ is the entire set of vertices.
  • $L \cap R$ is non-empty.
  • Any two vertices in $L$ can reach each other using only vertices in $L$.
  • Any two vertices in $R$ can reach each other using only vertices in $R$.

Given a weighted butterfly graph, find a subset of edges with the minimum total weight such that the graph remains a butterfly graph after keeping only these edges.

Input

The first line contains four positive integers $n, m, l, r$, representing the number of vertices, the number of edges, and the sizes of $L$ and $R$, respectively.

The next $m$ lines each contain three positive integers $u, v, w$, representing an edge.

The next line contains $l$ positive integers representing the vertex set $L$.

The next line contains $r$ positive integers representing the vertex set $R$.

Output

Output a single positive integer representing the minimum total edge weight.

Examples

Input 1

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

Output 1

9

Input 2

4 5 3 3
1 2 1
2 3 2
3 4 3
4 1 4
1 3 10
1 2 3
1 4 3

Output 2

10

Subtasks

For $100\%$ of the data, it is guaranteed that $1 \le n \le 10^5$; $n - 1 \le m \le 2 \times 10^5$; $1 \le l + r - n \le 11$; $1 \le u, v \le n$; $1 \le w \le 10^9$, and the given graph together with sets $L$ and $R$ forms a butterfly graph.

For $50\%$ of the data, it is guaranteed that $n = 100$, and for the other $50\%$ of the data, it is guaranteed that $n = 10^5$.

Each part has 10 test cases, where the values of $l + r - n$ are $1, 3, 4, 5, 6, 7, 8, 9, 10, 11$, respectively.

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.