#include #include #include #include #include #include #include #include #include static const int MOD = 1000000007; using ll = long long; using u32 = unsigned; using u64 = unsigned long long; using namespace std; template constexpr T INF = ::numeric_limits::max() / 32 * 15 + 208; template struct edge { int from, to; T cost; edge(int to, T cost) : from(-1), to(to), cost(cost) {} edge(int from, int to, T cost) : from(from), to(to), cost(cost) {} explicit operator int() const {return to;} }; class UnionFind { vector uni; int n; public: explicit UnionFind(int n) : uni(static_cast(n), -1) , n(n){}; int root(int a){ if (uni[a] < 0) return a; else return (uni[a] = root(uni[a])); } bool unite(int a, int b) { a = root(a); b = root(b); if(a == b) return false; if(uni[a] > uni[b]) swap(a, b); uni[a] += uni[b]; uni[b] = a; return true; } }; int main() { int n, m; cin >> n >> m; vector> E; for (int i = 0; i < m; ++i) { int s, t, d; scanf("%d %d %d", &s, &t, &d); E.emplace_back(s-1, t-1, d); } sort(E.begin(),E.end(), [&](edge &a, edge &b){ return a.cost > b.cost; }); UnionFind uf(n); int mx = INF; for (int i = 0; i < m; ++i) { if(uf.root(0) == uf.root(n-1)) break; else { uf.unite(E[i].from, E[i].to); mx = E[i].cost; } } vector> G(n); for (int i = 0; i < m; ++i) { if(E[i].cost >= mx){ G[E[i].from].emplace_back(E[i].to); G[E[i].to].emplace_back(E[i].from); } } vector dist(n, INF); queue Q; dist[0] = 0; Q.emplace(0); while(!Q.empty()){ int x = Q.front(); Q.pop(); for (auto &&y : G[x]) { if(dist[y] == INF) { dist[y] = dist[x]+1; Q.emplace(y); } } } printf("%d %d\n", mx, dist.back()); return 0; }