import java.util.ArrayList;
import java.util.Scanner;
public class Fr {
/**
* @param args
*/
public static void main
(String[] args
) { Scanner sc
= new Scanner
(System.
in);
while(sc.hasNext()){
int nodeCnt = sc.nextInt();
int centralNd = sc.nextInt();
// Fr.Node[] nodes = new Fr.Node[nodeCnt];
// Fr.Node root = nodes[centralNd];
int[][] 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] = price;
edges[nodeB][nodeA] = price;
}
long suma
= getMin
(centralNd
- 1, edges,
Long.
MAX_VALUE);
}
}
public static long getMin(int nodeIndex, int edges [][], 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, edges, 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);
}
}
}