## https://yukicoder.me/problems/no/1607 from collections import deque MAX_INT = 10 ** 18 def solve(N, next_nodes, K, value): # 01BFSで問題を解く dists = [MAX_INT ] * N dists[0] = 0 queue = deque() queue.append(0) while len(queue) > 0: v = queue.popleft() for w, cost in next_nodes[v]: if cost > value: if dists[w] > dists[v] + 1: dists[w] = dists[v] + 1 queue.append(w) else: if dists[w] > dists[v]: dists[w] = dists[v] queue.appendleft(w) return dists[N - 1] < K def main(): N, M, K = map(int, input().split()) edges = [] max_c = 0 for _ in range(M): u, v, c = map(int, input().split()) edges.append((u - 1, v - 1, c)) max_c = max(c, max_c) next_nodes = [[] for _ in range(N)] for u, v, c in edges: next_nodes[u].append((v, c)) next_nodes[v].append((u, c)) low = 0 high = max_c while high - low > 1: mid = (high + low) // 2 if solve(N, next_nodes, K, mid): high = mid else: low = mid if solve(N, next_nodes, K, low): print(low) else: print(high) if __name__ == "__main__": main()