luogu#P9926. [NFLSPC #6] 所以 k 小生成树怎么做?
[NFLSPC #6] 所以 k 小生成树怎么做?
Problem Description
Given a connected undirected weighted graph with no self-loops and no multiple edges, find the weights of the first smallest spanning trees.
- The weight of a spanning tree is the sum of the weights of all its edges.
- Two spanning trees are different if and only if there exists an edge that is in one spanning tree but not in the other.
- If the -th smallest spanning tree does not exist, output .
Input Format
The first line contains three integers .
The next lines each contain three integers , representing the two endpoints of an undirected edge and its weight.
Output Format
Output lines. The -th line contains one integer, representing the weight of the -th smallest spanning tree.
4 6 17
1 2 4
1 3 7
1 4 6
2 3 8
2 4 5
3 4 7
16
16
17
17
17
18
18
18
18
19
19
19
20
21
21
22
-1
Hint
For all testdata, , , , , , . The graph is guaranteed to be connected, with no self-loops and no multiple edges.
- Subtask 1 ( points): .
- Subtask 2 ( points): Each edge belongs to at most one simple cycle.
- Subtask 3 ( points): .
- Subtask 4 ( points): No special constraints.
Source: NFLSPC #6 A by Alex_Wei.
Translated by ChatGPT 5