Da este mensaje: java.lang.NullPointerException
Code: Select all
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
public class COJ_1480 {
static class par{
double a,b;
public par(){
a = b = 0;
}
}
static class trio{
double cost;
int n1,n2;
}
static par A[];
static trio V[];
static class DisjointsSets{
int DS[];
public DisjointsSets(int ne){
DS = new int[ne + 1];
for(int i = 1;i <= ne;i++){
DS[i] = i;
}
}
public int busca(int a){
if(a != DS[a])
DS[a] = busca(DS[a]);
return DS[a];
}
public void une(int a,int b){
DS[busca(a)] = busca(b);
}
}
public static void main(String []args) throws NumberFormatException, IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
int N = Integer.parseInt(in.readLine());
A = new par[N + 1];
DisjointsSets C = new DisjointsSets(N + 1);
int capacity = (N * (N - 1)) / 2 + 1;
V = new trio[capacity];
int cont = 0;
String E[];
for(int i = 1;i <= N;i++){
E = in.readLine().split(" ");
A[i].a = Double.parseDouble(E[0]); /*Runtime error in this line*/
A[i].b = Double.parseDouble(E[1]);
for(int j = 1;j < i;j++){
V[cont++].cost = dist(A[i],A[j]);
V[cont].n1 = i;
V[cont].n2 = j;
}
}
Arrays.sort(V);
double sol = 0;
for(int i = 0;i < capacity;i++){
if(C.busca(V[i].n1) != C.busca(V[i].n2)){
C.une(V[i].n1,V[i].n2);
sol += V[i].cost;
}
}
out.println(sol * 5);
}
private static double dist(par par, par par2) {
return Math.sqrt(Math.pow(par.a - par2.a,2) + Math.pow(par.b - par2.b,2));
}
}