#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; int ok = 0, ng = 1e9 + 5; int ans = -1; while (ok + 1 < ng) { int mid = (ng + ok) / 2; vector dist(n, INF); dist[0] = 0; deque dq; dq.push_back(0); while (!dq.empty()) { int v = dq.front(); dq.pop_front(); for (auto [u, w] : g[v]) { if (w < mid) { continue; } if (dist[u] > dist[v] + 1) { dist[u] = dist[v] + 1; dq.push_back(u); } } } if (dist[n - 1] < INF) { ok = mid; ans = dist[n - 1]; } else { ng = mid; } } cout << ok << " " << ans << endl; }