I tried to run this program for the primedistance question asked in august 13 challenge… I just visited every node and checked it’s distance from every other node… it’s giving correct answers for some test cases that I tried but on submitting it, it’s showing nzec error… help plz… here’s the code…

```
class CLASSNAME {
static long total=0;
public void solve(int testNumber, InputReader in, OutputWriter out) {
int n=in.readInt();
boolean[][] tree=new boolean[n+1][n+1];
boolean[] isPrime=IntegerUtils.generatePrimalityTable(100001);
boolean[] isVis;
for(int i=1;i<n;i++){
int a=in.readInt();int b=in.readInt();
tree[a][b]=tree[b][a]=true;
}
for(int i=1;i<=n;i++){
isVis=new boolean[n+1];
recurse(tree,isPrime,isVis,1,i);
}
//out.printLine(total);
out.printLine((total/2)/((n*(n-1))/2.0));
}
static void recurse(boolean[][] tree,boolean[] isPrime,boolean[] isVis,int sum,int level){
if(isVis[level])return;
isVis[level]=true;
//if(level>=tree[0].length)return;
for(int i=1;i<tree[0].length;i++){
if(tree[level][i]){
if(isPrime[sum] && !isVis[i]){
total++;
//System.out.println(level+" "+i+" "+sum);
}
recurse(tree,isPrime,isVis,sum+1,i);
}
}
}
}
```