#P6192. 【模板】最小斯坦纳树
【模板】最小斯坦纳树
Problem Description
You are given an undirected connected graph with vertices and weighted edges.
You are also given a set containing vertices. Choose a subgraph of such that:
- .
- is connected.
- The sum of edge weights in is minimized.
You only need to output the sum of edge weights in .
Input Format
The first line contains three integers , representing the number of vertices, the number of edges in , and the size of .
The next lines each contain three integers , indicating an undirected edge between vertices and with weight .
The next line contains distinct positive integers, representing the elements of .
Output Format
The first line contains one integer, the minimum possible sum of edge weights in .
7 7 4
1 2 3
2 3 2
4 3 9
2 6 2
4 5 3
6 5 2
7 6 4
2 4 7 5
11
Hint
[Sample Explanation]
The graph in the sample is shown in the figure below. The red vertices are the elements in , and the red edges are the elements in . In this case, the sum of all edge weights in is , which is the minimum.

[Constraints]
For of the testdata, $1\leq n\leq 100,\ \ 1\leq m\leq 500,\ \ 1\leq k\leq 10,\ \ 1\leq u,v\leq n,\ \ 1\leq w\leq 10^6$.
The given undirected graph is guaranteed to be connected, but there may be multiple edges and self-loops.
Translated by ChatGPT 5