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 {
/**
* @param args the command line arguments
*/
public static void main
(String[] args
) { Scanner sc
= new Scanner
(System.
in); while (true) {
int n, c;
int u, v, w;
if (!sc.hasNext()) break;
n = sc.nextInt();
c = sc.nextInt();
graph
= new ArrayList <LinkedList
<toEdge
>>(); 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 (graph.get(node).size() == 1)
for (toEdge e: graph.get(node)) {
if (e.V != parent) {
//System.out.println(e.value + ";" + minOfEdges(e.V, node));
sum
+= Math.
min(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 + '}';
}
}
}