Go to diff to previous submission
import java.util.ArrayList; import java.util.LinkedList; import java.util.Scanner; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author cteam92 */ public class Fr { static int c; /** * @param args the command line arguments */ while (true) { int n; int u, v, w; if (!sc.hasNext()) break; n = sc.nextInt(); c = sc.nextInt(); for (int i = 0; i < n; i++) { graph.add(new LinkedList<toEdge>()); } for (int i = 0; i < n - 1; i++) { u = sc.nextInt(); v = sc.nextInt(); w = sc.nextInt(); sc.nextLine(); LinkedList<toEdge> vertex; //System.out.println(u); //System.out.println(graph.); /*vertex = graph.get(u - 1); toEdge V2 = new toEdge(v - 1, w); vertex.add(V2); graph.set(u - 1, vertex);*/ graph.get(u-1).add(new toEdge(v-1, w)); graph.get(v-1).add(new toEdge(u-1, w)); } //visited = new boolean[n]; int sum = minOfEdges(c - 1, -1); } } public static int minOfEdges(int node, int parent) { int sum = 0; //System.out.println(node + " " + parent); if (node != c -1 && graph.get(node).size() == 1) for (toEdge e: graph.get(node)) { if (e.V != parent) { //System.out.println(e.value + ";" + minOfEdges(e.V, node)); } } return sum; } public static class toEdge { int V; int value; public toEdge(int V, int value) { this.V = V; this.value = value; } @Override return "toEdge{" + "V=" + V + ", value=" + value + '}'; } } }
--- c5.s889.cteam092.fr.java.0.Fr.java +++ c5.s903.cteam092.fr.java.0.Fr.java @@ -16,4 +16,5 @@ public class Fr { static ArrayList <LinkedList<toEdge>> graph; + static int c; /** @@ -23,5 +24,5 @@ Scanner sc = new Scanner(System.in); while (true) { - int n, c; + int n; int u, v, w; @@ -66,5 +67,5 @@ //System.out.println(node + " " + parent); - if (graph.get(node).size() == 1) + if (node != c -1 && graph.get(node).size() == 1) return Integer.MAX_VALUE; for (toEdge e: graph.get(node)) {