#asaporo2a. [asaporo2_a]Colorful MST
[asaporo2_a]Colorful MST
Problem Statement
Ringo has an undirected graph with vertices numbered and edges numbered . Edge connects Vertex and and has a length of .
Now, he is in the middle of painting these vertices in colors numbered . Vertex is already painted in Color , except when , in which case Vertex is not yet painted.
After he paints each vertex that is not yet painted in one of the colors, he will give to Snuke.
Based on , Snuke will make another undirected graph with vertices numbered and edges. Initially, there is no edge in . The -th edge will be added as follows:
- Let and be the colors of the two vertices connected by Edge in .
- Add an edge of length connecting Vertex and in .
What is the minimum possible sum of the lengths of the edges in the minimum spanning tree of ? If will not be connected regardless of how Ringo paints the vertices, print .
Constraints
- The given graph may NOT be simple or connected.
- All input values are integers.
Partial Scores
- In the test set worth points, and .
- In the test set worth another points, .
- In the test set worth another points, .
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
Sample Output 1
will only be connected when Vertex is painted in Color .
Sample Input 2
Sample Output 2
Regardless of how Ringo paints the vertices, two edges is not enough to connect four vertices as one.