1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #include <cmath>
5 #include <algorithm>
6 #include <climits>
7 #include <vector>
8 #include <queue>
9 #include <cstdlib>
10 #include <string>
11 #include <set>
12 #include <stack>
13 #define LL long long
14 #define pii pair<int,int>
15 #define INF 0x3f3f3f3f3f3f3fLL
16 using namespace std;
17 const int maxn = 600;
18 struct arc {
19 int to,next;
20 LL flow,cost;
21 arc(int x = 0,LL y = 0,LL z = 0,int nxt = -1) {
22 to = x;
23 flow = y;
24 cost = z;
25 next = nxt;
26 }
27 };
28 arc e[maxn*maxn];
29 int head[maxn],p[maxn];
30 LL d[maxn],dis[maxn][maxn];
31 int tot,S,T,N,M,K;
32 bool in[maxn];
33 void add(int u,int v,LL flow,LL cost) {
34 e[tot] = arc(v,flow,cost,head[u]);
35 head[u] = tot++;
36 e[tot] = arc(u,0,-cost,head[v]);
37 head[v] = tot++;
38 }
39 bool spfa() {
40 for(int i = 0; i < maxn; ++i) {
41 d[i] = INF;
42 p[i] = -1;
43 in[i] = false;
44 }
45 queue<int>q;
46 d[S] = 0;
47 q.push(S);
48 while(!q.empty()) {
49 int u = q.front();
50 q.pop();
51 in[u] = false;
52 for(int i = head[u]; ~i; i = e[i].next) {
53 if(e[i].flow && d[e[i].to] > d[u] + e[i].cost) {
54 d[e[i].to] = d[u] + e[i].cost;
55 p[e[i].to] = i;
56 if(!in[e[i].to]) {
57 in[e[i].to] = true;
58 q.push(e[i].to);
59 }
60 }
61 }
62 }
63 return p[T] > -1;
64 }
65 LL solve() {
66 LL ans = 0;
67 while(spfa()) {
68 for(int i = p[T]; ~i; i = p[e[i^1].to]) {
69 --e[i].flow;
70 ++e[i^1].flow;
71 }
72 ans += d[T];
73 }
74 return ans;
75 }
76 void Floyd() {
77 for(int k = 0; k <= N; ++k)
78 for(int i = 0; i <= N; ++i)
79 for(int j = 0; j <= N; ++j)
80 if(k <= i || k <= j)
81 dis[i][j] = min(dis[i][j],dis[i][k]+dis[k][j]);
82 }
83 int main() {
84 int u,v;
85 LL w;
86 while(~scanf("%d %d %d",&N,&M,&K)) {
87 memset(head,-1,sizeof(head));
88 for(int i = tot = 0; i <= N; ++i)
89 for(int j = 0; j <= N; ++j)
90 dis[i][j] = i == j?0:INF;
91 for(int i = tot = 0; i < M; ++i) {
92 cin>>u>>v>>w;
93 dis[u][v] = dis[v][u] = min(dis[u][v],w);
94 }
95 Floyd();
96 S = (N+1)<<1;
97 T = S|1;
98 for(int i = 0; i <= N; ++i)
99 add(i<<1,i<<1|1,1LL,-INF);
100 for(int i = 0; i <= N; ++i){
101 add(i<<1|1,T,1,0);
102 for(int j = i + 1; j <= N; ++j)
103 add(i<<1|1,j<<1,1,dis[i][j]);
104 }
105 add(S,1,K,0);
106 cout<<N*INF+solve()<<endl;;
107 }
108 return 0;
109 }