#include "bits/stdc++.h" //#include "atcoder/all" using namespace std; //using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; const int INF = 1e9; //const long long LINF = 1e18; //const bool debug = false; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n-1); i >= 0; --i) #define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define endl "\n" #define P pair template inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } struct Edge { int to, cost; Edge(int _to, int _cost) :to(_to), cost(_cost) {} }; vectorg[200005]; bool f(int x, int n, int k) { deque q; vector d(n, INF); d[0] = 0; q.push_back(0); while (!q.empty()) { int v = q.front(); q.pop_front(); for (auto ng : g[v]) { int nv = ng.to; if (ng.cost <= x) { //0 if (chmin(d[nv], d[v])) q.push_front(nv); } else { //1 if (chmin(d[nv], d[v] + 1)) q.push_back(nv); } } } return d[n - 1] < k; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m, k; cin >> n >> m >> k; rep(i, m) { int v, w, c; cin >> v >> w >> c; v--; w--; g[v].emplace_back(w, c); g[w].emplace_back(v, c); } int ng = -1; int ok = INF; while (1 < abs(ok - ng)) { int c = (ng + ok) / 2; if (f(c, n, k)) ok = c; else ng = c; } cout << ok << endl; return 0; }