#pragma GCC optimize("O3") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; using T = tuple; template inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;} template inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;} constexpr int MOD = 1e9 + 7; constexpr int inf = 1e9; constexpr long long INF = 1e18; #define all(a) (a).begin(), (a).end() int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; vector dijkstra(int s, int w, vector> &G){ int n = G.size(); vector dist(n, inf); priority_queue, greater

> que; que.emplace(0, s); while(que.size()){ int ccost, cv; tie(ccost, cv) = que.top(); que.pop(); if(dist[cv] < ccost) continue; for(auto nxt : G[cv]){ int nv, ncost, nw; tie(nv, ncost, nw) = nxt; if(w <= nw && ccost + ncost < dist[nv]){ dist[nv] = ccost + ncost; que.emplace(dist[nv], nv); } } } return dist; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int n, m; cin>>n>>m; vector> G(n); for(int i=0; i>s>>t>>d; s--, t--; G[s].emplace_back(t, 1, d); G[t].emplace_back(s, 1, d); } int ok = 1, ng = inf + 1; while(ng - ok > 1){ int mid = (ok + ng) / 2; auto dist = dijkstra(0, mid, G); if(dist[n - 1] != inf) ok = mid; else ng = mid; } auto ans = dijkstra(0, ok, G); cout << ok << " " << ans[n - 1] << endl; return 0; }