import sys from collections import deque def main(): input = sys.stdin.read().split() idx = 0 N = int(input[idx]); idx +=1 M = int(input[idx]); idx +=1 K = int(input[idx]); idx +=1 adj = [[] for _ in range(N+1)] max_c = 0 for _ in range(M): u = int(input[idx]); idx +=1 v = int(input[idx]); idx +=1 c = int(input[idx]); idx +=1 adj[u].append((v, c)) adj[v].append((u, c)) if c > max_c: max_c = c low = 0 high = max_c ans = max_c def min_bad_edges(x): inf = float('inf') dist = [inf] * (N + 1) dist[1] = 0 dq = deque() dq.append((0, 1)) while dq: d, u = dq.popleft() if d > dist[u]: continue for v, c in adj[u]: new_d = d + (1 if c > x else 0) if new_d < dist[v]: dist[v] = new_d if c > x: dq.append((new_d, v)) else: dq.appendleft((new_d, v)) return dist[N] while low <= high: mid = (low + high) // 2 mb = min_bad_edges(mid) if mb <= K - 1: ans = mid high = mid - 1 else: low = mid + 1 print(ans) if __name__ == '__main__': main()