#include "bits/stdc++.h" using namespace std; using ll = long long; const int INF = 1 << 30; void Main() { int n, m; cin >> n >> m; vector> graph(n, map()); for (int i = 0; i < m; ++i) { int s, t, d; cin >> s >> t >> d; --s; --t; if (graph[s].count(t) == 0) { graph[s].insert(make_pair(t, d)); graph[t].insert(make_pair(s, d)); } else { graph[s][t] = max(graph[s][t], d); graph[t][s] = max(graph[t][s], d); } } typedef pair weight_curr; priority_queue, greater> q; vector w(n, -1); int start = 0; q.push(make_pair(INF, start)); w[start] = INF; while (!q.empty()) { int weight = q.top().first; int curr = q.top().second; q.pop(); if (w[curr] > weight) { continue; } for (auto edge : graph[curr]) { int to = edge.first; int wei = edge.second; if (w[to] < min(w[curr], wei)) { w[to] = min(w[curr], wei); q.push(make_pair(w[to], to)); } } } int maxWeight = w[n - 1]; cout << maxWeight << " 1" << endl; return; vector> allowed(n, set()); for (int i = 0; i < n; ++i) { for (auto e : graph[i]) { if (e.second >= maxWeight) { allowed[i].insert(e.first); } } } typedef pair dist_curr; priority_queue, greater> aq; vector d(n, INF); aq.push(make_pair(0, start)); d[start] = 0; while (!aq.empty()) { int dist = aq.top().first; int curr = aq.top().second; aq.pop(); if (d[curr] < dist) { continue; } for (auto to : allowed[curr]) { if (d[to] > d[curr] + 1) { d[to] = d[curr] + 1; aq.push(make_pair(d[to], to)); } } } int minPath = d[n - 1]; cout << maxWeight << " " << minPath << endl; } int main() { std::cout << std::fixed << std::setprecision(15); Main(); return 0; }