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 int hlavna, poc; private static ArrayList<int[]>[] pole; private static boolean[] pouzite; String s; int a, b; int[] pomPole; int kde; int pomi; while (input.hasNextLine()) { s = input.nextLine(); pom = s.split(" "); pouzite = new boolean[poc]; for (int i = 0; i < poc; i++) { pole[i] = new ArrayList<>(); } 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); pomPole = new int[2]; pomPole[0] = kde; pomPole[1] = b; pole[a].add(pomPole); } } } private static int rek(int ja, int i) { pouzite[ja] = true; int sucet = 0; for (int[] is : pole[ja]) { if (pouzite[is[0]]) { continue; } sucet += rek(is[0], is[1]); } if (sucet == 0) { return i; } } }
--- c5.s881.cteam085.fr.java.0.Main.java +++ c5.s916.cteam085.fr.java.0.Main.java @@ -12,9 +15,7 @@ * @author kuric10 */ +@SuppressWarnings({"unchecked"}) public class Main { - /** - * @param args the command line arguments - */ private static int hlavna, poc; private static ArrayList<int[]>[] pole; @@ -22,5 +23,5 @@ public static void main(String[] args) { - // TODO code application logic here + String pom[]; String s; @@ -49,9 +50,5 @@ pomPole[1] = b; kde = Integer.parseInt(pom[0]) - 1; - /*if(pomPole[0]<kde){ - pomi=kde; - kde=pomPole[0]; - pomPole[0]=pomi; - }*/ + pole[kde].add(pomPole); pomPole = new int[2]; @@ -60,5 +57,5 @@ pole[a].add(pomPole); } - // vypis(); + System.out.println(rek(hlavna, 9999999)); } @@ -67,31 +64,21 @@ private static int rek(int ja, int i) { - //System.out.println(ja); + pouzite[ja] = true; - /* - if (pole[ja].isEmpty()) { - System.out.println(ja + " " + i); - return i; - }*/ + int sucet = 0; for (int[] is : pole[ja]) { - // System.out.println(ja); + if (pouzite[is[0]]) { - + continue; } sucet += rek(is[0], is[1]); } - if(sucet==0)return i; - // System.out.println(ja + " " + Math.min(i, sucet)); - return Math.min(i, sucet); - } - - public static void vypis() { - for (ArrayList<int[]> arrayList : pole) { - for (int[] is : arrayList) { - System.out.println(is[0]+" "+is[1]); - } + if (sucet == 0) { + return i; } + + return Math.min(i, sucet); } }