#include<iostream> #include<algorithm> #include<queue> #include<vector> #include<utility> #include<functional> usingnamespacestd; constint INF = 20344; constint MAX_V = 1500; structedge { int to, cost; edge(int to, int cost):to(to),cost(cost){} }; typedef pair<int, int> P; int V; vector<edge> G[MAX_V]; int d[MAX_V];
intdijkstra(int s, int t, int k){ priority_queue<P, vector<P>, greater<P> > que; fill(d + 1, d + V + 1, INF); d[s] = 0; que.push(P(0, s)); while (!que.empty()) { P p = que.top(); que.pop(); int v = p.second; if (d[v] < p.first) continue; for (int i = 0; i < G[v].size(); i++) { edge e = G[v][i]; if (d[e.to] > d[v] + (e.cost > k ? 1 : 0)) { d[e.to] = d[v] + (e.cost > k ? 1 : 0); que.push(P(d[e.to], e.to)); } } } return d[t]; } intmain(){ ios::sync_with_stdio(false); cin.tie(0); int N, P, K; cin >> N >> P >> K; V = N; for (int i = 0; i < P; i++){ int from, to, cost; cin >> from >> to >> cost; G[from].push_back(edge(to, cost)); G[to].push_back(edge(from, cost)); } int L = -1, R = 1000010; if (dijkstra(1, N, R) == INF) { cout << -1 << endl; return0; } while (L + 1 < R) { int mid = (L + R) >> 1; if (dijkstra(1, N, mid) <= K) R = mid; else L = mid; } cout << R << endl; }