## https://yukicoder.me/problems/no/1607 from collections import deque MAX_INT = 10 ** 18 def solve(N, edges, K, value): next_nodes = [[] for _ in range(N)] for u, v, c in edges: if c > value: next_nodes[u].append((v, 1)) next_nodes[v].append((u, 1)) else: next_nodes[u].append((v, 0)) next_nodes[v].append((u, 0)) # 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 == 1: if dists[w] > dists[v] + 1: dists[w] = dists[v] + 1 queue.append(w) elif cost == 0: 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) low = 0 high = max_c while high - low > 1: mid = (high + low) // 2 if solve(N, edges, K, mid): high = mid else: low = mid if solve(N, edges, K, low): print(low) else: print(high) if __name__ == "__main__": main()