using static System.Math; using System.Collections.Generic; using System.Linq; using System; public class Edge { public int to { get; set; } public long d { get; set; } } public class P { public int from { get; set; } public int step { get; set; } } public class Hello { public static int n, step; static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); n = int.Parse(line[0]); var m = int.Parse(line[1]); var aa = new List[n]; for (int i = 0; i < n; i++) aa[i] = new List(); for (int i = 0; i < m; i++) { line = Console.ReadLine().Trim().Split(' '); var s = int.Parse(line[0]) - 1; var t = int.Parse(line[1]) - 1; var d = int.Parse(line[2]); aa[s].Add(new Edge { to = t, d = d }); aa[t].Add(new Edge { to = s, d = d }); } getAns(aa); } static void getAns(List[] aa) { var ok = 1; var ng = 1000000001; while (ng - ok > 1) { var mid = ng + (ok - ng) / 2; if (check(aa, mid)) ok = mid; else ng = mid; } getSTEP(aa, ok); Console.WriteLine("{0} {1}", ok, step); } static void getSTEP(List[] aa, int t) { step = int.MaxValue; var visited = new bool[n]; var q = new Queue

(); q.Enqueue(new P { from = 0, step = 0 }); visited[0] = true; while (q.Count() > 0) { var w = q.Dequeue(); if (w.from == n - 1) { step = Min(step, w.step); continue; } foreach (var x in aa[w.from]) { if (t <= x.d && !visited[x.to] ) { q.Enqueue(new P { from = x.to, step = w.step + 1 }); visited[x.to] = true; } } } } static bool check(List[] aa, int t) { var visited = new bool[n]; var q = new Queue(); q.Enqueue(0); visited[0] = true; while (q.Count() > 0) { var w = q.Dequeue(); if (w == n - 1) { return true; } foreach (var x in aa[w]) { if (t <= x.d && !visited[x.to]) { q.Enqueue(x.to); visited[x.to] = true; } } } return false; } }