#P5633. 最小度限制生成树
最小度限制生成树
Description
You are given a weighted undirected graph with nodes and edges. You need to find a spanning tree such that the total edge weight is minimized, and the node with index is connected to exactly edges.
Input Format
The first line contains four numbers: .
The next lines each contain three integers: , meaning there is an edge between and with weight .
Output Format
Output one number: the total edge weight of a spanning tree that satisfies the requirement.
There may be cases where no solution exists. If there is no solution, output Impossible.
5 7 1 1
1 3 1
2 1 5
4 2 3
2 5 4
5 1 2
3 5 7
4 1 6
15
Hint
Constraints
For of the testdata, , .
For of the testdata, , .
For of the testdata, , , , .
Note
This problem includes hack testdata (Subtask ), worth points, but if you do not pass the hack testdata, it will not be considered as having passed this problem.
Translated by ChatGPT 5
京公网安备 11011102002149号