#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) #define srep(i,s,t) for (int i = s; i < (t); ++i) #define dsrep(i,t,s) for(int i = (t)-1; i >= (s); --i) #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define isin(x,l,r) ((l) <= (x) && (x) < (r)) int dx4[4]={1,0,-1,0}; int dy4[4]={0,-1,0,1}; using ll = long long; using uint = unsigned; using ull = unsigned long long; using P = pair; const ll LINF = 1001002003004005006ll; const int INF = 1001001001; const ll mod = 998244353; //////////////////////////////////////////// int n, m; vector

g[100005]; struct edge { int now, front, we; bool operator< (edge edge2) const { return we < edge2.we; } }; int di_m(int s, int goal) { priority_queue que; vector d(n, -1); que.push(edge{s, -1, INF}); while (!que.empty()) { edge e = que.top(); que.pop(); if(d[e.now] > e.we) continue; if(e.now == goal) return e.we; for(int i = 0; i < g[e.now].size(); i++) { auto [v, w] = g[e.now][i]; if(d[v] < min(e.we, w)) { d[v] = min(e.we, w); que.push(edge{v, e.now, d[v]}); } } } } int diks(int s, int goal, int ma) { priority_queue que; vector d(n, INF); que.push(edge{s, -1, 0}); d[s] = 0; while (!que.empty()) { edge e = que.top(); que.pop(); if(d[e.now] < e.we) continue; if(e.now == goal) return e.we; for(int i = 0; i < g[e.now].size(); i++) { auto [v, w] = g[e.now][i]; if(w >= ma && d[v] > e.we + 1) { d[v] = e.we + 1; que.push(edge{v, e.now, d[v]}); } } } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> m; int a, b, c; rep(i, m) { cin >> a >> b >> c; a--; b--; g[a].push_back(P(b, c)); g[b].push_back(P(a, c)); } int ma = di_m(0, n - 1); cout << ma << " " << diks(0, n - 1, ma) << endl; }