from collections import defaultdict, deque def bsearch(low: int, high: int, fun, is_complement=False) -> int: def pred(x: int) -> bool: return not fun(x) if is_complement else fun(x) lo = low hi = high res = low while lo <= hi: m = (lo + hi) // 2 if pred(m): res = max(res, m) lo = m + 1 else: hi = m - 1 return res + 1 if is_complement else res def calc(weight: int) -> int: q = deque([(0, 0)]) used = {0} while q: v, step = q.popleft() if v == N-1: return step for to, d in adj[v]: if weight > d: continue if to in used: continue used.add(to) q.append((to, step+1)) return -1 N, M = map(int, input().split()) adj = defaultdict(list) for _ in range(M): s, t, d = map(int, input().split()) s -= 1 t -= 1 adj[s].append((t, d)) adj[t].append((s, d)) w = bsearch(1, 10**9, lambda x: calc(x) > 0) step = calc(w) print(w, step)