Source code for submission s916

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.  
  6. package fr;
  7.  
  8.  
  9.  
  10. import java.util.ArrayList;
  11. import java.util.Scanner;
  12.  
  13. /**
  14.  *
  15.  * @author kuric10
  16.  */
  17. @SuppressWarnings({"unchecked"})
  18. public class Main {
  19.  
  20. private static int hlavna, poc;
  21. private static ArrayList<int[]>[] pole;
  22. private static boolean[] pouzite;
  23.  
  24. public static void main(String[] args) {
  25.  
  26. String pom[];
  27. String s;
  28. int a, b;
  29. Scanner input = new Scanner(System.in);
  30. int[] pomPole;
  31. int kde;
  32. int pomi;
  33. while (input.hasNextLine()) {
  34. s = input.nextLine();
  35. pom = s.split(" ");
  36. hlavna = Integer.parseInt(pom[1]) - 1;
  37. poc = Integer.parseInt(pom[0]);
  38. pole = new ArrayList[poc];
  39. pouzite = new boolean[poc];
  40. for (int i = 0; i < poc; i++) {
  41. pole[i] = new ArrayList<>();
  42. }
  43. for (int i = 0; i < poc - 1; i++) {
  44. pomPole = new int[2];
  45. s = input.nextLine();
  46. pom = s.split(" ");
  47. a = Integer.parseInt(pom[1]) - 1;
  48. b = Integer.parseInt(pom[2]);
  49. pomPole[0] = a;
  50. pomPole[1] = b;
  51. kde = Integer.parseInt(pom[0]) - 1;
  52.  
  53. pole[kde].add(pomPole);
  54. pomPole = new int[2];
  55. pomPole[0] = kde;
  56. pomPole[1] = b;
  57. pole[a].add(pomPole);
  58. }
  59.  
  60. System.out.println(rek(hlavna, 9999999));
  61. }
  62.  
  63. }
  64.  
  65. private static int rek(int ja, int i) {
  66.  
  67. pouzite[ja] = true;
  68.  
  69. int sucet = 0;
  70. for (int[] is : pole[ja]) {
  71.  
  72. if (pouzite[is[0]]) {
  73.  
  74. continue;
  75. }
  76. sucet += rek(is[0], is[1]);
  77. }
  78. if (sucet == 0) {
  79. return i;
  80. }
  81.  
  82. return Math.min(i, sucet);
  83. }
  84. }
  85.  

Diff to submission s881

Main.java

--- 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);
     }
 }