Go to diff to previous submission
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package fn; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Scanner; /** * * @author kuric10 */ public class Main { /** * @param args the command line arguments */ // TODO code application logic here // String s=input.readLine(); int poc[] = new int[10001]; //int spoje[][] int max; int prve; 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 } s=input.readLine(); }*/ 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); for (int i = 0; i < links; i++) { prve = in.nextInt(); druhe = in.nextInt(); if (prve > druhe) { pom = prve; prve = druhe; druhe = pom; } 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) { } else { } for (int i = 0; i < max + 1; i++) { poc[i] = 0; } a.clear(); } } }
--- 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(); + } }