fork download
  1.  
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main(String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. int n,m,t,a,b,i,j;
  14. t=Integer.parseInt(br.readLine());
  15. for(int kk=0;kk<t;kk++)
  16. {
  17. String []nos=br.readLine().split(" ");
  18. n=Integer.parseInt(nos[0]);
  19. m=Integer.parseInt(nos[1]);
  20. int [][]c=new int[n+1][n+1];
  21. //for(i=0;i<n+1;i++)
  22. // c[i]=new int[n+1];
  23. for(i=0;i<n+1;i++)
  24. {
  25. for(j=0;j<n+1;j++)
  26. {
  27. c[i][j]=0;
  28. }
  29. }
  30. for(int ii=0;ii<m;ii++)
  31. {
  32. String []no=br.readLine().split(" ");
  33. a=Integer.parseInt(no[0]);
  34. b=Integer.parseInt(no[1]);
  35. c[a-1][b-1]++;
  36. c[b-1][a-1]++;
  37. }
  38. int flg=0,cnt=0;
  39. for(i=0;i<n+1;i++)
  40. {
  41. cnt=0;
  42. for(j=0;j<n+1;j++)
  43. {
  44. if(c[i][j]>0)
  45. cnt+=c[i][j];
  46. }
  47. if(cnt%2!=0)
  48. flg++;
  49. }
  50. if(flg==2|| flg==0)
  51. System.out.println("Yes");
  52. else
  53. System.out.println("No");
  54. }
  55. }
  56. }
  57.  
Success #stdin #stdout 0.11s 320512KB
stdin
3
4 4
1 2
2 3
2 3
3 4
4 5
1 2
2 3
2 3
3 4
3 4
7 9
1 2
2 3
3 4
4 5
5 7
7 6
6 1
6 2
2 6
stdout
No
Yes
Yes