#include <vector>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <stack>
#include <list>
#include <numeric>
#include <algorithm>
#include <random>
#include <chrono>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <climits>
#include <cctype>
#include <cmath>
#include <ctime>
#include <cassert>
using namespace std;
#define ULL unsigned long long
#define LL long long
#define PII pair <int, int>
#define VB vector <bool>
#define VI vector <int>
#define VLL vector <LL>
#define VD vector <double>
#define VS vector <string>
#define VPII vector <pair <int, int> >
#define VVI vector < VI >
#define VVB vector < VB >
#define SI set < int >
#define USI unordered_set <int>
#define MII map <int, int>
#define UMII unordered_map <int, int>
#define MS multiset
#define US unordered_set
#define UM unordered_map
#define UMS unordered_multiset
#define UMM unordered_multimap
#define FORN(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define SZ size()
#define BG begin()
#define EN end()
#define CL clear()
#define X first
#define Y second
#define RS resize
#define PB push_back
#define MP make_pair
#define ALL(x) x.begin(), x.end()
#define INS insert
#define ER erase
#define CNT count
struct Path
{
int node;
LL remaining;
int charges;
};
int n, m, k;
vector <VPII> g;
LL capacity;
vector <VLL> best;
VI least;
bool bellmanFord(int source)
{
best.CL, best.RS(n + 1, VLL(k + 1, -1));
least.CL, least.RS(n + 1, n);
queue <Path> fifo;
Path aux = {source, capacity, 1};
best[source][1] = capacity;
least[source] = 1;
fifo.push(aux);
USI reached;
while (!fifo.empty())
{
Path head = fifo.front();
reached.INS(head.node);
if (reached.SZ == n) return true;
fifo.pop();
for (auto [next, cost] : g[head.node])
{
if (cost > capacity) continue;
LL rem;
int chr;
if (head.remaining >= cost)
{
rem = head.remaining - cost;
chr = head.charges;
}
else
{
rem = capacity - cost;
chr = head.charges + 1;
}
if (chr > k) continue;
if (chr > least[next]) continue;
if (best[next][chr] == -1 || best[next][chr] < rem)
{
best[next][chr] = rem;
least[next] = min(least[next], chr);
aux = {next, rem, chr};
fifo.push(aux);
}
}
}
return reached.SZ == n;
}
bool check()
{
FOR(i, 1, n)
if (!bellmanFord(i)) return false;
return true;
}
int main()
{
cin >> n >> m >> k;
g.RS(n + 1);
FOR(i, 1, m)
{
int u, v, c;
cin >> u >> v >> c;
g[u].PB({v, c});
g[v].PB({u, c});
}
LL sol = 0;
FORD(i, 36, 0)
{
capacity = sol + (1LL << i);
if (!check()) sol += (1LL << i);
}
cout << sol + 1;
return 0;
}