fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Graph
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. int ii = 0, k = 0;
  10. Boolean p = true;
  11. Scanner in = new Scanner(System.in);
  12. int n = in.nextInt();
  13. int m = in.nextInt();
  14. int[] v = new int[m], g = new int[m];
  15. for (int i = 0; i < m; i ++)
  16. {
  17. v[i] = in.nextInt();
  18. g[i] = in.nextInt();
  19. }
  20. while (p)
  21. {
  22. for (int j = ii+1; j < m; j ++)
  23. {
  24. if ((v[ii] == v[j]) && (g[ii] == g[j]))
  25. {
  26. k++;
  27. System.out.println("YES");
  28. p=false; //Выход из цикла.
  29. }
  30. }
  31. ii ++;
  32. if (ii == m) break; //Условие окончания цикла.
  33. }
  34. if (k == 0) System.out.println("NO");
  35. }
  36. }
Success #stdin #stdout 0.15s 321344KB
stdin
3 4
1 2
2 3
1 3
2 3
stdout
YES