Source code for submission s1027

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 class vrchol{
  21. public ArrayList<int []> susedia;
  22.  
  23. public vrchol() {
  24. susedia= new ArrayList<int []>();
  25. }
  26.  
  27. }
  28.  
  29. private static int hlavna, poc;
  30. // private static ArrayList<int[]>[] pole;
  31. private static boolean[] pouzite;
  32. // private static ArrayList<ArrayList<int[]>> pole;
  33. private static ArrayList<vrchol> pole;
  34.  
  35. public static void main(String[] args) {
  36.  
  37. String pom[];
  38. String s;
  39. int a, b;
  40. Scanner input = new Scanner(System.in);
  41. int[] pomPole;
  42. int kde;
  43. int pomi;
  44. while (input.hasNextLine()) {
  45. s = input.nextLine();
  46. pom = s.split(" ");
  47. hlavna = Integer.parseInt(pom[1]) - 1;
  48. poc = Integer.parseInt(pom[0]);
  49. pole= new ArrayList<vrchol>();
  50. //pole= new ArrayList<ArrayList>();
  51.  
  52. // pole = new ArrayList[poc];
  53.  
  54. pouzite = new boolean[poc];
  55. for (int i = 0; i < poc; i++) {
  56. pole.add(new vrchol());
  57. }
  58. for (int i = 0; i < poc - 1; i++) {
  59. pomPole = new int[2];
  60. s = input.nextLine();
  61. pom = s.split(" ");
  62. a = Integer.parseInt(pom[1]) - 1;
  63. b = Integer.parseInt(pom[2]);
  64. pomPole[0] = a;
  65. pomPole[1] = b;
  66. kde = Integer.parseInt(pom[0]) - 1;
  67.  
  68. // pole[kde].add(pomPole);
  69. pole.get(kde).susedia.add(pomPole);
  70. pomPole = new int[2];
  71. pomPole[0] = kde;
  72. pomPole[1] = b;
  73. //pole[a].add(pomPole);
  74. pole.get(a).susedia.add(pomPole);
  75. }
  76.  
  77. System.out.println(rek(hlavna, 9999999));
  78. }
  79.  
  80. }
  81.  
  82. private static int rek(int ja, int i) {
  83.  
  84. pouzite[ja] = true;
  85.  
  86. int sucet = 0;
  87. for (int[] is : pole.get(ja).susedia) {
  88.  
  89. if (pouzite[is[0]]) {
  90.  
  91. continue;
  92. }
  93. sucet += rek(is[0], is[1]);
  94. }
  95. if (sucet == 0) {
  96. return i;
  97. }
  98.  
  99. return Math.min(i, sucet);
  100. }
  101. }
  102.  

Diff to submission s947

Main.java

--- 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]]) {