#include #include using namespace std; using namespace atcoder; int main(){ // input + prep int n,m; cin >> n >> m; map>> edge; while(m--){ int s,t,d; cin >> s >> t >> d; edge[-d].emplace_back(--s,--t); } // solve #1 dsu uf(n); vector> g(n); int w = -1; for(auto p : edge){ w = -p.first; for(auto [u,v] : p.second){ uf.merge(u,v); g[u].push_back(v); g[v].push_back(u); } if(uf.same(0,n-1)) break; } // solve #2 vector dist(n,-1); queue> q; q.emplace(0,0); dist[0] = 0; while(!q.empty()){ auto[now,stp] = q.front(); q.pop(); for(auto nxt : g[now]){ if(dist[nxt] == -1){ dist[nxt] = stp+1; q.emplace(nxt,stp+1); } } } // output cout << w << " " << dist.back() << endl; }