#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; } bool operator> (edge edge2) const { return we > edge2.we; } }; int diks(int s, int goal, int ma) { priority_queue, greater

> que; vector d(n, INF); que.push(P(s, 0)); d[s] = 0; while (!que.empty()) { P e = que.top(); que.pop(); if(e.first == goal) return e.second; for(int i = 0; i < g[e.first].size(); i++) { auto [v, w] = g[e.first][i]; if(w >= ma && d[v] > e.second + 1) { d[v] = e.second + 1; que.push(P(v, d[v])); } } } return -1; } 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 l = 0, r = 1e9 + 1, count; while(r - 1 > l) { int mid = (r + l) / 2; int t = diks(0, n - 1, mid); if(t == -1) { r = mid; } else { l = mid; count = t; } } cout << l << " " << count << endl; }