Go to diff to previous submission
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package fr; import java.util.ArrayList; import java.util.Scanner; /** * * @author kuric10 */ //@SuppressWarnings({"unchecked"}) public class Main { private static class vrchol{ public ArrayList<int []> susedia; public vrchol() { susedia= new ArrayList<int []>(); } } private static int hlavna, poc; // private static ArrayList<int[]>[] pole; private static boolean[] pouzite; // private static ArrayList<ArrayList<int[]>> pole; private static ArrayList<vrchol> pole; String s; int a, b; int[] pomPole; int kde; int pomi; while (input.hasNextLine()) { s = input.nextLine(); pom = s.split(" "); pole= new ArrayList<vrchol>(); //pole= new ArrayList<ArrayList>(); // pole = new ArrayList[poc]; pouzite = new boolean[poc]; for (int i = 0; i < poc; i++) { pole.add(new vrchol()); } for (int i = 0; i < poc - 1; i++) { pomPole = new int[2]; s = input.nextLine(); pom = s.split(" "); pomPole[0] = a; pomPole[1] = b; // pole[kde].add(pomPole); pole.get(kde).susedia.add(pomPole); pomPole = new int[2]; pomPole[0] = kde; pomPole[1] = b; //pole[a].add(pomPole); pole.get(a).susedia.add(pomPole); } } } private static int rek(int ja, int i) { pouzite[ja] = true; int sucet = 0; for (int[] is : pole.get(ja).susedia) { if (pouzite[is[0]]) { continue; } sucet += rek(is[0], is[1]); } if (sucet == 0) { return i; } } }
--- c5.s947.cteam085.fr.java.0.Main.java +++ c5.s1027.cteam085.fr.java.0.Main.java @@ -15,11 +15,22 @@ * @author kuric10 */ -@SuppressWarnings({"unchecked"}) +//@SuppressWarnings({"unchecked"}) public class Main { + private static class vrchol{ + public ArrayList<int []> susedia; + + public vrchol() { + susedia= new ArrayList<int []>(); + } + + } + private static int hlavna, poc; - private static ArrayList<int[]>[] pole; + // private static ArrayList<int[]>[] pole; private static boolean[] pouzite; - + // private static ArrayList<ArrayList<int[]>> pole; + private static ArrayList<vrchol> pole; + public static void main(String[] args) { @@ -36,8 +47,12 @@ hlavna = Integer.parseInt(pom[1]) - 1; poc = Integer.parseInt(pom[0]); - pole = new ArrayList[poc]; + pole= new ArrayList<vrchol>(); + //pole= new ArrayList<ArrayList>(); + + // pole = new ArrayList[poc]; + pouzite = new boolean[poc]; for (int i = 0; i < poc; i++) { - pole[i] = new ArrayList<>(); + pole.add(new vrchol()); } for (int i = 0; i < poc - 1; i++) { @@ -51,9 +66,11 @@ kde = Integer.parseInt(pom[0]) - 1; - pole[kde].add(pomPole); + // pole[kde].add(pomPole); + pole.get(kde).susedia.add(pomPole); pomPole = new int[2]; pomPole[0] = kde; pomPole[1] = b; - pole[a].add(pomPole); + //pole[a].add(pomPole); + pole.get(a).susedia.add(pomPole); } @@ -68,5 +85,5 @@ int sucet = 0; - for (int[] is : pole[ja]) { + for (int[] is : pole.get(ja).susedia) { if (pouzite[is[0]]) {