ONE

Time limit1sMemory limit128 MB

Problem

A city consists of intersections connected by streets.

After heavy snowfall, the streets that must be cleared are chosen so that the number of streets is as small as possible while every pair of intersections is still connected, i.e. between every two intersections there is exactly one path. (With N intersections this is exactly N-1 streets forming a tree.)

A single snow plough, driven by Mirko, starts at one of the intersections. It burns one litre of fuel per metre driven (even when driving along a street that has already been cleared), and it must clear every street on the list. Once all streets are cleared, the plough is parked at the last intersection it visited.

Compute the minimum total amount of fuel the snow plough must spend to clear all the streets.

Input

The first line contains two integers N and S (1 <= N <= 100000, 1 <= S <= N): the total number of intersections and the index of the starting intersection. Intersections are numbered from 1 to N.

Each of the next N-1 lines contains three integers A, B and C, meaning that intersections A and B are directly connected by a street of length C metres (1 <= C <= 1000).

Output

Print a single integer: the minimum amount of fuel needed to clear all the streets.