GETTING A NZEC ERROR

I am new to java…

please help me out to avoid nzec error…

question link : http://www.codechef.com/problems/WSC

my code :-

import java.util.Scanner;

public class Main

{

public static void main(String[] args)

{

  Scanner kb = new Scanner(System.in);
  int t = kb.nextInt();
  //boolean ans;
  while(t-->0)
  {
	  int n = kb.nextInt();
	  int m = kb.nextInt();
	  if(m<2)
	  {
		  int x = kb.nextInt();
		  int y = kb.nextInt();
		  System.out.println("YES");
	  }
	  else if(m>2)
	  {
		  for(int i =0;i<m;i++)
		  {
			  int x = kb.nextInt();
			  int y = kb.nextInt();
		  }
		  System.out.println("NO");
	  }
	  else if(m==2)
	  {
		  int x = kb.nextInt();
		  int y = kb.nextInt();
		  int a = kb.nextInt();
		  int b = kb.nextInt();
		  if(x==a||y==b||x==b||y==a)
			  System.out.println("YES");
		  else
			  System.out.println("NO");
	  }
		  
	  }
  }

}

3 Likes

For M=0, there will be no relations. So you need to output some answer and read values for next test case. But your code reads X and Y(Part of same test case). link.

1 Like