#P4854. MloVtry的咸鱼树
MloVtry的咸鱼树
Description
As the saying goes, you reap what you sow. MloVtry cut off half of itself and buried it in the ground, and thus obtained a “Salted Fish Tree” with vertices.
However, because MloVtry only buried half of itself, this Salted Fish Tree is incomplete — it has even broken into edges.
As a salted fish that could cause cancer, MloVtry certainly wants a Salted Fish Tree to show its identity.
MloVtry has roughly estimated the cost of connecting two vertices and wants to know the minimum total cost needed to assemble a Salted Fish Tree.
Note that the edges on the Salted Fish Tree have strong opinions about MloVtry. Each edge specifies a vertex set . Only after MloVtry has connected all vertices in this special set into some set can this edge be added to that set .
MloVtry buried its brain in the ground, so you have to solve this problem.
Input Format
The first line contains integers .
The next lines each contain integers , denoting an undirected edge of length between and , which can only be chosen after the vertex set has already been selected (this set is represented by a binary number; vertex corresponds to the first bit, and so on).
Output Format
Output a single integer, the minimum total cost. If there is no solution, output .
2 7
1 2 1 14
2 1 2 11
2 2 1 18
2 1 2 16
2 1 2 12
2 1 2 16
2 1 3 13
11
Hint
Constraints: , .
The testdata guarantees that all values are within the range of a 32-bit int.
Translated by ChatGPT 5
京公网安备 11011102002149号