Import java. Io. bufferedinputstream;
Import java. util. collections;
Public class prim {
Static int [] [] arr;
Static Boolean flag []; // used to mark whether node I is overwritten
Static int N;
Static int sum;
Static final int maxint = integer. max_value;
Public static void main (string [] ARGs ){
S = new second (New bufferedinputstream (system. In ));
While (S. hasnextint ()){
N = S. nextint ();
Arr = new int [n + 1] [n + 1];
Flag = new Boolean [n + 1];
For (INT I = 1; I <= N; I ++)
For (Int J = 1; j <= N; j ++)
Arr [I] [J] = S. nextint (); // starts from subscript 1
Sum = 0;
Flag [1] = true; // select the first node
For (int K = 1; k <n; k ++) {// loop n-1 times
Int min = maxint, min_ I = 0;
For (INT I = 1; I <= N; I ++ ){
If (! Flag [I] & arr [1] [I] <min ){
Min = arr [1] [I];
Min_ I = I;
}
}
System. Out. println ("min_ I:" + min_ I );
Flag [min_ I] = true; // overwrite the node
For (INT I = 1; I <= N; I ++) {// The distance from the node not covered by the update. It is updated every time a vertex is added.
If (! Flag [I] & arr [1] [I]> arr [min_ I] [I])
Arr [1] [I] = arr [min_ I] [I];
System. Out. Print ("arr [1] [" + I + "]" + arr [1] [I] + "");
}
System. Out. println ();
Sum + = arr [1] [min_ I]; // Add the weight
}
System. Out. println (SUM );
}
}
}