#include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; struct UnionFind { vector data; UnionFind(int size) : data(size, -1) {} bool unionSet(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool findSet(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } }; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n, m; cin >> n >> m; vector s(m), t(m), d(m); for(int i = 0;i < m; i++){ cin >> s[i] >> t[i] >> d[i]; s[i]--; t[i]--; } int l = 1, r = (1e9)+1000; while(r-l > 1){ UnionFind uf(n); int c = (r+l)/2; for(int i = 0; i < m; i++){ if(d[i] >= c) uf.unionSet(s[i], t[i]); } if(uf.findSet(0, n-1)) l = c; else r = c; } vector> g(n); for(int i = 0; i < m; i++){ if(d[i] >= l) { g[s[i]].push_back(t[i]); g[t[i]].push_back(s[i]); } } vector used(n, false); vector dist(n); queue que; que.push(0); dist[0] = 0; used[0] = true; while(!que.empty()){ int v = que.front(); que.pop(); for(int to : g[v]){ if(!used[to]){ used[to] = true; dist[to] = dist[v]+1; que.push(to); } } } cout << l << ' ' << dist[n-1] << endl; }