#include #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--) #define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++) #define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--) #define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++) #define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++) #define ALL(x) x.begin(), x.end() using ll = long long; using namespace std; int fc(const vector>> &gr, int mid) { int n = gr.size(); vector chk(n, -1); queue q; chk.at(0) = 0; q.push(0); while(!q.empty()) { auto now = q.front(); q.pop(); for(auto [nx, c] : gr.at(now)) { if(c < mid) continue; if(chk.at(nx) != -1) continue; chk.at(nx) = chk.at(now) + 1; q.push(nx); } } return chk.back(); } int main() { int n, m; cin >> n >> m; vector gr(n, vector>()); rep(i, m) { int s, t, d; cin >> s >> t >> d; s--; t--; gr.at(s).push_back({t, d}); gr.at(t).push_back({s, d}); } int ok = 1, ng = 1001001001; int ans = 0; while(ng - ok > 1) { int mid = (ok+ng)/2; int r = fc(gr, mid); // cerr << r << " " << mid << endl; if(r != -1) { ok = mid; ans = r; } else ng = mid; } cout << ok << " " << ans << endl; return 0; }