import sys def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LC(): return list(input()) def IC(): return [int(c) for c in input()] def MI(): return map(int, sys.stdin.readline().split()) INF = float('inf') MOD = 10**9 + 7 def solve(): N,M = MI() Graph = [[] for i in range(N+1)] for m in range(M): S,T,D = MI() Graph[S].append((T,D)) Graph[T].append((S, D)) from collections import deque def is_ok(arg): Q = deque() Seen = [False for i in range(N + 1)] Dist = [INF for i in range(N+1)] Dist[1] = 0 s = 1 Seen[s] = True Q.append(s) #始点をキューに入れる while len(Q) > 0: now = Q.popleft() #隣接グラフGraphの場合 for next,weight in Graph[now]: if(weight 1): mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok W = meguru_bisect(10**9 + 1, 1) Q = deque() Seen = [False for i in range(N + 1)] Dist = [INF for i in range(N + 1)] Dist[1] = 0 s = 1 Seen[s] = True Q.append(s) # 始点をキューに入れる while len(Q) > 0: now = Q.popleft() # 隣接グラフGraphの場合 for next, weight in Graph[now]: if (weight < W): continue if (Seen[next] == False): # 未探索ならば Seen[next] = True Q.append(next) # 始点からの距離とかの計算はここで Dist[next] = min(Dist[now] + 1, Dist[next]) print(W,Dist[N]) return solve()