#include using namespace std; const int N = 1e5 + 11; vector e[N]; struct edge { int u, v, w; bool operator <(const edge &e) const { return w > e.w; } }a[N]; int p[N]; int find(int x) { if(p[x] == x) return x; return p[x] = find(p[x]); } int dis[N]; int main() { ios::sync_with_stdio(0); int n, m; cin >> n >> m; for(int i = 0; i < m; i ++) { cin >> a[i].u >> a[i].v >> a[i].w; } sort(a, a + m); iota(p, p + n + 1, 0); auto add = [&](int u, int v) { e[u].push_back(v); e[v].push_back(u); u = find(u); v = find(v); if(u != v) p[u] = v; }; int p = 0, w = 0; while(find(1) != find(n)) { w = a[p].w; add(a[p].u, a[p].v); p ++; } while(p != m && a[p].w == w) { add(a[p].u, a[p].v); p ++; } fill(dis, dis + n + 1, 1e8); dis[1] = 0; queue q; q.push(1); while(!q.empty()) { int x = q.front(); q.pop(); for(int i : e[x]) { if(dis[i] > dis[x] + 1) { dis[i] = dis[x] + 1; q.push(i); } } } cout << w << ' ' << dis[n] << '\n'; }