#include #define rep(i, l, r) for (int i = (l); i < (r); i++) using namespace std; typedef long long ll; typedef pair P; struct edge { ll to, cost; }; const int MAX_V =100000; const ll INF = 1LL<<60; int V; vector G[MAX_V]; ll d[MAX_V]; void dijkstra(ll s) { // greater

を指定することでfirstが小さい順に取り出せるようにする priority_queue, greater

> que; fill(d, d + V, 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; rep(i,0,G[v].size()) { edge e = G[v][i]; if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; que.push(P(d[e.to], e.to)); } } } } int main() { int N, M, K, u, v, c; cin >> N >> M >> K; V = N; vector cmin(N, 1e9); rep(i, 0, M) { cin >> u >> v >> c; u--; v--; G[u].push_back({v, 1}); G[v].push_back({u, 1}); cmin[u] = min(cmin[u], c); cmin[v] = min(cmin[v], c); } dijkstra(N - 1); if (d[0] < K) { cout << 0 << endl; return 0; } int ans = 1e9; rep(i, 0, N) { if (d[i] < K) ans = min(ans, cmin[i]); } cout << ans << endl; }