#include using namespace std; int main() { int n,m; cin >> n >> m; vector>>road(n); for(int i = 0; i < m; i++) { int s,t,d; cin >> s >> t >> d; s--; t--; road[s].push_back({t,d}); road[t].push_back({s,d}); } int l = 0,r = 1000000001; while (l+1 < r) { int mid = (l+r)/2; vectordist(n,100005); dist[0] = 0; queueque; que.push(0); while (!que.empty()) { int x = que.front(); que.pop(); for(int i = 0; i < road[x].size(); i++) { if(road[x][i].second >= mid && dist[road[x][i].first] == 100005) { dist[road[x][i].first] = dist[x]+1; que.push(road[x][i].first); } } } if(dist[n-1] != 100005) { l = mid; } else { r = mid; } } vectordist(n,100005); dist[0] = 0; queueque; que.push(0); while (!que.empty()) { int x = que.front(); que.pop(); for(int i = 0; i < road[x].size(); i++) { if(road[x][i].second >= l && dist[road[x][i].first] == 100005) { dist[road[x][i].first] = dist[x]+1; que.push(road[x][i].first); } } } cout << l << " " << dist[n-1] << endl; }