1 #include<cstdio>
2 #include<cstdlib>
3 #include<cmath>
4 #include<cstring>
5 #include<algorithm>
6 #include<iostream>
7 #include<vector>
8 #include<map>
9 #include<set>
10 #include<queue>
11 #define inf 1000000000
12 #define maxn 500
13 #define maxm 100000
14 #define eps 1e-10
15 #define ll long long
16 #define pa pair<int,int>
17 using namespace std;
18 inline int read()
19 {
20 int x=0,f=1;char ch=getchar();
21 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
22 while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}
23 return x*f;
24 }
25 int n,m,k,tot=1,s,t,ss,head[maxn],q[maxn],from[maxn],f[maxn][maxn];
26 bool v[maxn];
27 ll d[maxn],mincost;
28 struct edge{int from,next,go,v,c;}e[2*maxm];
29 void ins(int x,int y,int z,int w)
30 {
31 e[++tot].go=y;e[tot].from=x;e[tot].v=z;e[tot].c=w;e[tot].next=head[x];head[x]=tot;
32 }
33 void insert(int x,int y,int z,int w)
34 {
35 ins(x,y,z,w);ins(y,x,0,-w);
36 }
37 bool spfa()
38 {
39 for (int i=s;i<=ss;i++)d[i]=inf;
40 memset(v,0,sizeof(v));
41 int l=0,r=1,y;q[1]=s;d[s]=0;v[0]=1;
42 while(l!=r)
43 {
44 int x=q[++l];if(l==maxn)l=0;v[x]=0;
45 for (int i=head[x];i;i=e[i].next)
46 if(e[i].v&&d[x]+e[i].c<d[y=e[i].go])
47 {
48 d[y]=d[x]+e[i].c;from[y]=i;
49 if(!v[y]){v[y]=1;q[++r]=y;if(r==maxn)r=0;}
50 }
51 }
52 return d[t]!=inf;
53 }
54 void mcf()
55 {
56 while(spfa())
57 {
58 int tmp=inf;
59 for(int i=from[t];i;i=from[e[i].from]) tmp=min(tmp,e[i].v);
60 mincost+=d[t]*tmp;
61 for(int i=from[t];i;i=from[e[i].from]){e[i].v-=tmp;e[i^1].v+=tmp;}
62 }
63 }
64 int main()
65 {
66 freopen("input.txt","r",stdin);
67 freopen("output.txt","w",stdout);
68 n=read();m=read();k=read();
69 memset(f,60,sizeof(f));
70 for(int i=1;i<=m;i++)
71 {
72 int x=read(),y=read(),z=read();
73 f[x][y]=min(f[x][y],z);f[y][x]=min(f[y][x],z);
74 }
75 s=0;t=2*n+1;ss=2*n+2;insert(s,ss,k,0);
76 for(int k=0;k<=n;k++)
77 for(int i=0;i<=n;i++)
78 for(int j=k;j<=n;j++)
79 f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
80 for(int i=1;i<=n;i++)insert(s,i,1,0);
81 for(int i=1;i<=n;i++)insert(ss,i+n,1,f[0][i]);
82 for(int i=1;i<=n;i++)insert(i+n,t,1,0);
83 for(int i=1;i<=n;i++)
84 for(int j=i+1;j<=n;j++)
85 insert(i,j+n,1,f[i][j]);
86 mcf();
87 printf("%lld\n",mincost);
88 return 0;
89 }