hi
please i try to solve the bug's life problem i do this code `
`import java.io.PrintWriter;
import java.util.Scanner;
public class Buglife {
int[][] insecte=new int[2000][2000];
int []sex;
public Buglife() {
try{
Scanner in = new Scanner(System.in);
PrintWriter out=new PrintWriter (System.out);
int nb = in.nextInt();
for(int i=1;i<=nb;i++){
int n=in.nextInt();
int m=in.nextInt();
sex=new int[n+1];
for(int j=1;j<=n;j++){
sex[j]=0;
for(int k=1;k<=n;k++){
insecte[j][k]=0;
}
}
for(int y=1;y<=m;y++){
int a=in.nextInt();
int b=in.nextInt();
insecte[a][b]=insecte[b][a]=1;
}
boolean res=true;
for(int h=1;res && h<=n;h++){
if(sex[h]==0){
sex[h]=1;
res= dfs(h,n);
}
}
out.println("Scenario #:"+i);
if(res) out.println("No suspicious bugs found!");
else out.println("Suspicious bugs found!");
}
out.flush();
in.close();
}
catch(Exception e){
return;
}
}
public boolean dfs(int a,int n){
for (int b = 1; b <= n; b++) {
if (insecte[a][b]==0)
continue;
if(sex[b]==0){
sex[b]=-sex[a];
if(dfs(b,n)==false) return false;
}
else if((sex[a]+sex[b])!=0) return false;
}
return true;
}
public static void main(String[] args) {
new Buglife();
}
}
and i got this error
"time limit exceeded" any help thanks in advance