import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Comparator;
class Line implements Comparable
<Line
>{ int v1, v2, len, act;
Line(int v1,
int v2,
int len,
int act
) { this.v1 = v1;
this.v2 = v2;
this.len = len;
this.act = act;
}
@Override
public int compareTo
(Line arg0
) { return len - arg0.len;
}
}
public class Spider {
/**
* @param args
*/
int n, l, v1, v2, len, act;
int[] nodes;
//int[] v1;
//int[] v2;
//int[] len;
//int[] act;
int result = 0;
while (true)
{
s = br.readLine();
if (s == null) break;
nodes = new int[n];
// v1 = new int[l];
// v2 = new int[l];
// len = new int[l];
// act = new int[l];
for (int i=0; i<n; i++) nodes[i] = i;
for (int i=0; i<l; i++) {
s = br.readLine();
sp = s.split(" ");
act = 1;
lines
[i
] = new Line(v1, v2, len, act
); }
// spojitost
for (int i=0; i<l; i++) {
nodes[ lines[i].v2 ] = nodes[ lines[i].v1 ]; // stejna komponenta
}
boolean ok = true;
for (int i=1; i<n; i++) {
if (nodes[i-1] != nodes[i]) {
ok = false;
break;
}
}
if (!ok) {
System.
out.
println("disconnect"); }
else {
for (int i=0; i<n; i++) nodes[i] = 0;
int maxi = -1;
for (int i=1; i<l; i++) {
if (lines[i].len > max) {
max = lines[i].len;
maxi = i;
}
}
// vyradit max hranu
lines[maxi].act = 0;
nodes[ lines[maxi].v2 ] = 1;
nodes[ lines[maxi].v1 ] = 1;
// mst
for (int i=0; i<lines.length; i++) {
if (lines[i].act == 1) {
// nova minimalni, zkusime pridat do kostry
if (!(nodes[ lines[i].v1 ] == 1 && nodes[ lines[i].v2 ] == 1)) {
//System.out.println((lines[i].v1+1) + " -> " + (lines[i].v2+1));
//System.out.println(">" + (nodes[ lines[i].v1]+1));
//System.out.println(">" + (nodes[ lines[i].v2]+1));
result += lines[i].len;
lines[i].act = 0;
nodes[ lines[i].v2 ] = 1;
nodes[ lines[i].v1 ] = 1;
}
else {
lines[i].act = 0;
}
}
}
System.
out.
println(result
- max
);
}
}
}
}