#P5633. 最小度限制生成树

最小度限制生成树

Description

You are given a weighted undirected graph with nn nodes and mm edges. You need to find a spanning tree such that the total edge weight is minimized, and the node with index ss is connected to exactly kk edges.

Input Format

The first line contains four numbers: n,m,s,kn,m,s,k.

The next mm lines each contain three integers: u,v,wu,v,w, meaning there is an edge between uu and vv with weight ww.

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 20%20\% of the testdata, n10n \le 10, m30m \le 30.
For 50%50\% of the testdata, n1000n \le 1000, m5000m \le 5000.
For 100%100\% of the testdata, 1sn5×1041\leq s \leq n \le 5\times 10^4, 1m5×1051\leq m \le 5\times 10^5 , 1k1001\leq k \le 100, 0w3×1040\leq w\leq 3\times 10^4.

Note

This problem includes hack testdata (Subtask 22), worth 00 points, but if you do not pass the hack testdata, it will not be considered as having passed this problem.

Translated by ChatGPT 5