#include #include #include #include using namespace std; #define MAX_N 100000 struct Q { int i, d; }; int n; vector V[MAX_N]; int bfs(int w) { bool B[n]; for (int i=0; i < n ; i++) B[i] = false; vector fw; fw.push_back(0); int depth = 1; while (true) { vector newfw; for (int i = 0; i < fw.size(); i++) { int j = fw[i]; B[j] = true; for (int k = 0; k < V[j].size(); k++) { Q q = V[j][k]; if (q.d >= w) { if (q.i == n - 1) { return depth; } if (!B[q.i]) { newfw.push_back(q.i); } } } } if (newfw.size() == 0) { depth = 0; break; } fw = newfw; depth++; } return depth; } int main() { int m; cin >> n >> m; for (int i=0; i < n; i++) { V[i] = vector(); } int max_d = 0; int min_d = 0x7fffffff; for (int i=0; i < m; i++) { int s, t, d; std::cin >> s >> t >> d; V[s-1].push_back(Q{t-1, d}); V[t-1].push_back(Q{s-1, d}); max_d = max_d > d ? max_d : d; min_d = min_d < d ? min_d : d; } Q l = Q{min_d - 1, 0}; Q r = Q{max_d + 1, 0}; while (r.i - l.i > 1) { int mid = (r.i + l.i) / 2; int c = bfs(mid); if (c == 0) { r.i = mid; r.d = 0; } else { l.i = mid; l.d = c; } } std::cout << l.i << ' ' << l.d << endl; }