#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;
struct Node {
int node;
unsigned int weight;
Node() : node(0), weight(0) {}
Node(int node, int weight) : node(node), weight(weight) {}
};
typedef vector<Node> Nodes;
typedef vector<Nodes> Map;
Map map;
int N, C;
int search(int node, unsigned int W, int parent)
{
bool hasChildren = false;
unsigned int effort = 0;
// compute effort
for (Nodes::iterator it = map[node].begin(); it != map[node].end(); ++it) {
if (it->node != parent) {
hasChildren = true;
//cout << "node=" << it->node << " weight=" << it->weight << endl;
effort += search(it->node, it->weight, node);
}
}
if (!hasChildren) return W;
//cout << "current=" << W << " computed=" << effort << endl;
return W < effort ? W : effort;
}
int main()
{
ios_base::sync_with_stdio(false);
while (cin >> N >> C) {
int a, b, effort;
int n;
map.clear();
map.resize(N + 1);
for (n = 0; n < N - 1; ++n) {
cin >> a >> b >> effort;
map[a].push_back(Node(b, effort));
map[b].push_back(Node(a, effort));
}
cout << search(C, 0xFFFFFFFF, 0) << "\n";
}
cout.flush();
return 0;
}