1 /****************************************************
2
3 Author : Coolxxx
4 Copyright 2017 by Coolxxx. All rights reserved.
5 BLOG : http://blog.csdn.net/u010568270
6
7 ****************************************************/
8 #include<bits/stdc++.h>
9 #pragma comment(linker,"/STACK:1024000000,1024000000")
10 #define abs(a) ((a)>0?(a):(-(a)))
11 #define lowbit(a) (a&(-a))
12 #define sqr(a) ((a)*(a))
13 #define mem(a,b) memset(a,b,sizeof(a))
14 #define eps (1e-8)
15 #define J 10000
16 #define mod 1000000007
17 #define MAX 0x7f7f7f7f
18 #define PI 3.14159265358979323
19 #define N 304
20 using namespace std;
21 typedef long long LL;
22 double anss;
23 LL aans;
24 int cas,cass;
25 int n,m,lll,ans;
26 int l[N],r[N],q[N],s[N],fa[N];
27 int ma[N][N];
28 int f[N][N][2];
29 void dfs(int now,int ff)
30 {
31 if(!now)return;
32 fa[now]=ff;
33 if(l[now])dfs(l[now],now);
34 if(r[now])dfs(r[now],now);
35 s[now]=s[l[now]]+s[r[now]]+1;
36 q[++lll]=now;
37 }
38 int main()
39 {
40 #ifndef ONLINE_JUDGE
41 freopen("1.txt","r",stdin);
42 // freopen("2.txt","w",stdout);
43 #endif
44 int i,j,k;
45 int x,y,z;
46 // for(scanf("%d",&cass);cass;cass--)
47 // for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
48 // while(~scanf("%s",s))
49 while(~scanf("%d",&n))
50 {
51 mem(l,0);mem(r,0);mem(f,1);
52 scanf("%d%d",&m,&cas);
53 cass=(m==2);
54 for(i=1;i<n;i++)
55 {
56 scanf("%d%d%d",&x,&y,&z);
57 if(x>y)swap(x,y);
58 if(!l[x])
59 {
60 l[x]=y;
61 ma[x][y]=ma[y][x]=z;
62 }
63 else
64 {
65 r[y]=l[x];
66 l[x]=y;
67 ma[x][y]=ma[y][x]=z;
68 ma[y][r[y]]=ma[r[y]][y]=ma[x][r[y]];
69 }
70 }
71 if(m+cas>n){puts("-1");continue;}
72 lll=0;
73 dfs(1,0);
74 f[0][0][0]=f[0][0][1]=0;
75 for(x=1;x<=lll;x++)
76 {
77 i=q[x];
78 for(j=0;j<=min(cas,s[i]);j++)
79 {
80 for(y=0;y<=j;y++)
81 {
82 for(k=0;k<=1;k++)
83 {
84 f[i][j][k]=min(f[i][j][k],f[l[i]][y][0]+f[r[i]][j-y][k]+ma[i][fa[i]]*(k==0)*cass);
85 if(y>0)f[i][j][k]=min(f[i][j][k],f[l[i]][y-1][1]+f[r[i]][j-y][k]+ma[i][fa[i]]*(k==1));
86 }
87 }
88 }
89 }
90 printf("%d\n",f[l[1]][cas-1][1]);
91 }
92 return 0;
93 }
94 /*
95 //
96
97 //
98 */