Source code for submission s965

Go to diff to previous submission

Fr.java

  1. import java.util.Scanner;
  2.  
  3.  
  4.  
  5. public class Fr {
  6.  
  7. public static int[][] edges;
  8.  
  9. public static void main(String[] args) {
  10. Scanner sc = new Scanner(System.in);
  11.  
  12. while(sc.hasNext()){
  13. int nodeCnt = sc.nextInt();
  14. int centralNd = sc.nextInt();
  15.  
  16. edges = new int[nodeCnt][nodeCnt];
  17.  
  18. for(int i = 0; i < nodeCnt - 1; i++){
  19. int nodeA = sc.nextInt() - 1;
  20. int nodeB = sc.nextInt() - 1;
  21. int price = sc.nextInt();
  22.  
  23. edges[nodeA][nodeB] = edges[nodeB][nodeA] = price;
  24. }
  25.  
  26. long suma = getMin(centralNd - 1, Long.MAX_VALUE);
  27. System.out.println(suma);
  28.  
  29.  
  30.  
  31. }
  32.  
  33.  
  34. }
  35.  
  36. public static long getMin(int nodeIndex, long tmpMin){
  37. long suma = 0;
  38.  
  39. for(int i = 0; i < edges.length; i++){
  40. if(i != nodeIndex){
  41. if(edges[nodeIndex][i] != 0){
  42. int tmpVal = edges[nodeIndex][i];
  43. edges[nodeIndex][i] = 0;
  44. edges[i][nodeIndex] = 0;
  45.  
  46. suma += getMin(i, tmpVal);
  47. }
  48. }
  49.  
  50. }
  51.  
  52.  
  53.  
  54. if(suma == 0){
  55. return tmpMin;
  56. }else{
  57. return tmpMin < suma ? tmpMin : suma;
  58. }
  59. }
  60.  
  61. /*class Node {
  62. ArrayList<Node> childrens;
  63. long price;
  64.  
  65. public Node(long price) {
  66. childrens = new ArrayList<Fr.Node>();
  67. this.price = price;
  68. }
  69.  
  70. public void addChildren(Node n){
  71. childrens.add(n);
  72. }
  73. }*/
  74.  
  75. }
  76.  

Diff to submission s935

Fr.java

--- c5.s935.cteam059.fr.java.0.Fr.java
+++ c5.s965.cteam059.fr.java.0.Fr.java
@@ -1,3 +1,2 @@
-import java.util.ArrayList;
 import java.util.Scanner;
 
@@ -6,7 +5,6 @@
 public class Fr {
 
-        /**
-         * @param args
-         */
+        public static int[][] edges;
+
         public static void main(String[] args) {
                 Scanner sc = new Scanner(System.in);
@@ -16,8 +14,5 @@
                         int centralNd = sc.nextInt();
                         
-//                      Fr.Node[] nodes = new Fr.Node[nodeCnt];
-//                      Fr.Node root = nodes[centralNd];
-                        
-                        int[][] edges = new int[nodeCnt][nodeCnt];
+                        edges = new int[nodeCnt][nodeCnt];
                         
                         for(int i = 0; i < nodeCnt - 1; i++){
@@ -26,10 +21,8 @@
                                 int price = sc.nextInt();
                                 
-                                edges[nodeA][nodeB] = price;
-                                edges[nodeB][nodeA] = price;
+                                edges[nodeA][nodeB] = edges[nodeB][nodeA] = price;
                         }
                         
-                        long suma = getMin(centralNd - 1, edges, Long.MAX_VALUE);
-                        
+                        long suma = getMin(centralNd - 1, Long.MAX_VALUE);
                         System.out.println(suma);
                         
@@ -41,5 +34,5 @@
         }
         
-        public static long getMin(int nodeIndex, int edges [][], long tmpMin){
+        public static long getMin(int nodeIndex, long tmpMin){
                 long suma = 0;
                 
@@ -51,5 +44,5 @@
                                         edges[i][nodeIndex] = 0;
 
-                                        suma += getMin(i, edges, tmpVal);
+                                        suma += getMin(i, tmpVal);
                                 }
                         }
@@ -66,5 +59,5 @@
         }
 
-        class Node {
+        /*class Node {
                 ArrayList<Node> childrens;
                 long price;
@@ -78,5 +71,5 @@
                         childrens.add(n);
                 }
-        }
+        }*/
         
 }