#include using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); int n, m; cin >> n >> m; vector>> g(n); for (int i = 0; i < m; i++) { int s, t, d; cin >> s >> t >> d; s--, t--; g[s].push_back({t, d}); g[t].push_back({s, d}); } const int INF = 1e9; vector> dist(n, {0, 1e9}); vector vis(n, false); dist[0] = {1e9, 0}; using tiii = tuple; priority_queue, greater> pq; pq.push({-1e9, 0, 0}); while (!pq.empty()) { auto [ma, d, u] = pq.top(); pq.pop(); if (vis[u]) { continue; } vis[u] = true; ma = -ma; for (auto [v, w] : g[u]) { int ma_new = min(ma, w); if (dist[v].first < ma_new) { dist[v] = {ma_new, dist[u].second + 1}; pq.push({-ma_new, dist[v].second, v}); } else if (dist[v].first == ma_new) { dist[v].second = min(dist[v].second, dist[u].second + 1); pq.push({-ma_new, dist[v].second, v}); } } } cout << dist[n - 1].first << " " << dist[n - 1].second << endl; }