import sys input = sys.stdin.readline from operator import itemgetter N,K=map(int,input().split()) E=[tuple(map(int,input().split())) for i in range(N-1)] EDGE=[[] for i in range(N)] for a,b,e in E: a-=1 b-=1 EDGE[a].append((b,e)) EDGE[b].append((a,e)) QUE=[0] Parent=[-1]*(N+1) Parent[0]=0 TOP_SORT=[] while QUE: x=QUE.pop() TOP_SORT.append(x) for to,w in EDGE[x]: if Parent[to]==-1: Parent[to]=x,w QUE.append(to) EW=[0]*N for n in TOP_SORT[1:][::-1]: #print(n,Parent[n]) if EW[n]==0: EW[n]=1 EW[Parent[n][0]]+=EW[n] XX=[] for i in range(1,N): XX.append((Parent[i][1],EW[i])) XC=[[] for i in range(101)] for x,c in XX: XC[c].append(x) ANS=0 cost=0 for i in range(100,-1,-1): if sum(XC[i])+cost