using System.Collections.Generic; using System.Linq; using System; public class UnionFind { private int[] data; public UnionFind(int size) { data = new int[size]; for (int i = 0; i < size; i++) data[i] = -1; } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x != y) { if (data[y] < data[x]) { var tmp = y; y = x; x = tmp; } data[x] += data[y]; data[y] = x; } return x != y; } public bool IsSameGroup(int x, int y) => Root(x) == Root(y); public int Root(int x) => data[x] < 0 ? x : data[x] = Root(data[x]); public int getMem(int x) => -data[Root(x)]; } public class E2 { public int n1 { get; set; } public int n2 { get; set; } public int d { get; set; } } public class Edge { public int to { get; set; } public int d { get; set; } } public class P { public int from { get; set; } public int step { get; set; } } public class Hello { public static int n, m; static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); n = int.Parse(line[0]); m = int.Parse(line[1]); var aa = new List[n]; for (int i = 0; i < n; i++) aa[i] = new List(); var e2s = new E2[m]; 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 }); e2s[i] = new E2 { n1 = s, n2 = t, d = d }; } var W = getW(e2s); var step = getSTEP(aa, W); Console.WriteLine("{0} {1}", W, step); } static int getW(E2[] e2s) { var uf = new UnionFind(n); foreach( var x in e2s.OrderByDescending(x =>x.d)) { uf.Unite(x.n1, x.n2); if (uf.Root(n - 1) == uf.Root(0)) return x.d; } return 0; } static int getSTEP(List[] aa, int t) { 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) return w.step; 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; } } } return 0; } }