Source code for submission s604

Go to diff to previous submission

Main.java

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package fn;
  6.  
  7. import java.io.BufferedReader;
  8. import java.io.InputStreamReader;
  9. import java.util.ArrayList;
  10. import java.util.Scanner;
  11.  
  12. /**
  13.  *
  14.  * @author kuric10
  15.  */
  16. public class Main {
  17.  
  18. /**
  19.   * @param args the command line arguments
  20.   */
  21. public static void main(String[] args) throws Exception {
  22. // TODO code application logic here
  23. // String s=input.readLine();
  24. String pole[];
  25. int poc[] = new int[10001];
  26. //int spoje[][]
  27. int max;
  28. int prve;
  29. int druhe;
  30. int links;
  31. /* while(1==1){
  32.   prve=input.read();
  33.   input.read();
  34.   druhe=input.read();
  35.   input.read();
  36.   }*/
  37.  
  38. /* while(!s.equals(null)){
  39.   pole=s.split(" ");
  40.   max=Integer.parseInt(pole[0]);//nebol bz lepsi scanner ??
  41.   links=Integer.parseInt(pole[1]);
  42.   for (int i = 0; i < links; i++) {
  43.   s=input.readLine();
  44.   pole
  45.   }
  46.  
  47.   s=input.readLine();
  48.   }*/
  49. Scanner in = new Scanner(System.in);
  50. ArrayList<int[]> a = new ArrayList<int[]>();
  51. int[] pomPole;
  52. int pom;
  53. boolean b;
  54. while (in.hasNextInt()) {
  55. b = false;
  56. max = in.nextInt();
  57. links = in.nextInt();
  58. // System.out.println(links);
  59. for (int i = 0; i < links; i++) {
  60. prve = in.nextInt();
  61. druhe = in.nextInt();
  62. if (prve > druhe) {
  63. pom = prve;
  64. prve = druhe;
  65. druhe = pom;
  66. }
  67. pomPole = new int[2];
  68. pomPole[0] = prve;
  69. pomPole[1] = druhe;
  70. //
  71. if (!a.contains(i)) {
  72. poc[prve]++;
  73. poc[druhe]++;
  74. a.add(pomPole);
  75. if (poc[prve] == 4 || poc[druhe] == 4) {
  76. b = true;
  77. //break;
  78. }
  79. }
  80. }
  81. if (b) {
  82. System.out.println("YES");
  83. } else {
  84. System.out.println("NO");
  85. }
  86. for (int i = 0; i < max + 1; i++) {
  87. poc[i] = 0;
  88. }
  89. a.clear();
  90.  
  91. }
  92. }
  93. }
  94.  

Diff to submission s581

Main.java

--- c5.s581.cteam085.fn.java.0.Main.java
+++ c5.s604.cteam085.fn.java.0.Main.java
@@ -7,4 +7,5 @@
 import java.io.BufferedReader;
 import java.io.InputStreamReader;
+import java.util.ArrayList;
 import java.util.Scanner;
 
@@ -18,10 +19,10 @@
      * @param args the command line arguments
      */
-    public static void main(String[] args)throws Exception{
+    public static void main(String[] args) throws Exception {
         // TODO code application logic here
-        BufferedReader input= new BufferedReader(new InputStreamReader(System.in));
-       // String s=input.readLine();
+        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
+        // String s=input.readLine();
         String pole[];
-        int poc[]=new int[10001];
+        int poc[] = new int[10001];
         //int spoje[][]
         int max;
@@ -29,54 +30,64 @@
         int druhe;
         int links;
-       /* while(1==1){
-            prve=input.read();
-            input.read();
-            druhe=input.read();
-            input.read();
-        }*/
-        
-      /*  while(!s.equals(null)){
-            pole=s.split(" ");
-            max=Integer.parseInt(pole[0]);//nebol bz lepsi scanner ??
-            links=Integer.parseInt(pole[1]);
-            for (int i = 0; i < links; i++) {
-                s=input.readLine();
-                pole
-            }
+        /* while(1==1){
+         prve=input.read();
+         input.read();
+         druhe=input.read();
+         input.read();
+         }*/
+
+        /*  while(!s.equals(null)){
+         pole=s.split(" ");
+         max=Integer.parseInt(pole[0]);//nebol bz lepsi scanner ??
+         links=Integer.parseInt(pole[1]);
+         for (int i = 0; i < links; i++) {
+         s=input.readLine();
+         pole
+         }
             
-            s=input.readLine();
-        }*/
-        Scanner in= new  Scanner(System.in);
+         s=input.readLine();
+         }*/
+        Scanner in = new Scanner(System.in);
+        ArrayList<int[]> a = new ArrayList<int[]>();
+        int[] pomPole;
         int pom;
         boolean b;
-        while(in.hasNextInt()){
-            b=false;
-            max=in.nextInt();
-            links=in.nextInt();
-           // System.out.println(links);
+        while (in.hasNextInt()) {
+            b = false;
+            max = in.nextInt();
+            links = in.nextInt();
+            // System.out.println(links);
             for (int i = 0; i < links; i++) {
-                prve=in.nextInt();
-                druhe=in.nextInt();
-                if(prve>druhe){
-                    pom=prve;
-                    prve=druhe;
-                    druhe=pom;
+                prve = in.nextInt();
+                druhe = in.nextInt();
+                if (prve > druhe) {
+                    pom = prve;
+                    prve = druhe;
+                    druhe = pom;
                 }
-                poc[prve]++;
-                poc[druhe]++;
-                if(poc[prve]==4 || poc[druhe]==4){
-                    b=true;
-                    break;
+                pomPole = new int[2];
+                pomPole[0] = prve;
+                pomPole[1] = druhe;
+                //
+                if (!a.contains(i)) {
+                    poc[prve]++;
+                    poc[druhe]++;
+                    a.add(pomPole);
+                    if (poc[prve] == 4 || poc[druhe] == 4) {
+                        b = true;
+                        //break;
+                    }
                 }
             }
-            if(b){
+            if (b) {
                 System.out.println("YES");
-            }else{
+            } else {
                 System.out.println("NO");
             }
-            for (int i = 0; i < max+1; i++) {
-                poc[i]=0;
+            for (int i = 0; i < max + 1; i++) {
+                poc[i] = 0;
             }
-            
+            a.clear();
+
         }
     }