Source code for submission s947

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 s916

Main.java