Go to diff to previous submission
import java.util.Scanner; public class Fr { public static int[][] edges; while(sc.hasNext()){ int nodeCnt = sc.nextInt(); int centralNd = sc.nextInt(); edges = new int[nodeCnt][nodeCnt]; for(int i = 0; i < nodeCnt - 1; i++){ int nodeA = sc.nextInt() - 1; int nodeB = sc.nextInt() - 1; int price = sc.nextInt(); edges[nodeA][nodeB] = edges[nodeB][nodeA] = price; } } } public static long getMin(int nodeIndex, long tmpMin){ long suma = 0; for(int i = 0; i < edges.length; i++){ if(i != nodeIndex){ if(edges[nodeIndex][i] != 0){ int tmpVal = edges[nodeIndex][i]; edges[nodeIndex][i] = 0; edges[i][nodeIndex] = 0; suma += getMin(i, tmpVal); } } } if(suma == 0){ return tmpMin; }else{ return tmpMin < suma ? tmpMin : suma; } } /*class Node { ArrayList<Node> childrens; long price; public Node(long price) { childrens = new ArrayList<Fr.Node>(); this.price = price; } public void addChildren(Node n){ childrens.add(n); } }*/ }
--- 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); } - } + }*/ }