import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author cteam038
*/
public class Fr {
static class Edge {
public final int sNode;
public final int dNode;
public final int weight;
public Edge(int sNode, int dNode, int weight) {
this.sNode = sNode;
this.dNode = dNode;
this.weight = weight;
}
return sNode + " " + dNode;
}
}
private static Map
<Integer, List
<Edge
>> edges
;
private static void addToMap(int node, Edge edge) {
//System.out.println("add "+node+" edge "+edge);
if (!edges.containsKey(node)) {
edges.put(node, new ArrayList<Edge>());
}
edges.get(node).add(edge);
}
private static int traverse(int node, int topWeight, Edge parent) {
//System.out.println("node "+node);
if (parent != null && edges.get(node).size() <= 1) {
// sme na listu
//System.out.println("return");
return topWeight;
}
int downWeight = 0;
for (Edge child : edges.get(node)) {
//System.out.println("child "+child);
if (child != parent) {
int dNode = child.sNode == node ? child.dNode : child.sNode;
// System.out.println("goto node "+dNode);
downWeight
+= traverse
(dNode,
Math.
min(topWeight,child.
weight), child
);// System.out.println("back from "+dNode);
}
}
// System.out.println("returning (non-leaf)");
return Math.
min(downWeight, topWeight
); }
public static void main
(String [] args
) { Scanner scanner
= new Scanner
(System.
in); while (scanner.hasNext()) {
edges
= new HashMap
<Integer, List
<Edge
>>(); int nodes = scanner.nextInt();
int central = scanner.nextInt();
for (int i=0; i < nodes - 1; i++) {
Edge edge = new Edge(scanner.nextInt(), scanner.nextInt(), scanner.nextInt());
addToMap(edge.sNode, edge);
addToMap(edge.dNode, edge);
}
}
}
}