#ifndef _DEBUG #define _DEBUG #include __FILE__ signed main() { int N, M; cin >> N >> M; vector> V(M); for (int i = 0; i < M; i++) { int a, b, c; cin >> a >> b >> c, a--, b--; V.at(i) = {a, b, c}; } auto f = [&](long mid) { Dijkstra D(N); for (const auto& [a, b, c] : V) { if (c >= mid) D.add_edge(a, b, 1); } auto ans = D.solve(0).at(N - 1); if (ans == LONG_MAX) return false; return true; }; long ok = 0, ng = INT_MAX; while (abs(ok - ng) > 1) { long mid = (ok + ng) / 2; (f(mid)) ? ok = mid : ng = mid; } auto f2 = [&](long mid) { Dijkstra D(N); for (const auto& [a, b, c] : V) { if (c >= mid) D.add_edge(a, b, 1); } auto ans = D.solve(0).at(N - 1); return ans; }; cout << ok << " " << f2(ok) << "\n"; } #else // #undef _DEBUG #pragma GCC diagnostic warning "-Wextra" #pragma GCC diagnostic warning "-Wshadow" #include using namespace std; template class Dijkstra { private: using edge = tuple; vector> G; vector D; public: Dijkstra(int v) : G(v), D(v, numeric_limits::max()) {} void add_edge(int from, int to, T cost) { G[from].push_back({to, cost}); G[to].push_back({from, cost}); } vector solve(int s) { D[s] = 0; using pti = pair; priority_queue, greater> que; que.push({0, s}); while (que.size()) { auto [dist, now] = que.top(); que.pop(); if (dist > D[now]) continue; for (const auto& [to, cost] : G[now]) { if (D[now] + cost < D[to]) { D[to] = D[now] + cost; que.push({D[to], to}); } } } return D; } }; struct io_setup { io_setup() { cin.tie(nullptr)->sync_with_stdio(false); } } io_setup; template bool cmin(A& a, const B& b) { if (a > b) return a = b, true; return false; } template bool cmax(A& a, const B& b) { if (a < b) return a = b, true; return false; } template ostream& operator<<(ostream& os, const pair& p); template ostream& operator<<(ostream& os, const tuple& t); template ostream& operator<<(ostream& os, const tuple& t); #define foreach(it, a) for (auto it = a.begin(); it != a.end(); it++) ostream& operator<<(ostream& os, const vector& vec) { os << "{"; foreach (it, vec) { os << (it == vec.begin() ? "" : " ") << *it; } return os << "}"; } template ostream& operator<<(ostream& os, const vector& vec) { os << "{"; foreach (it, vec) { os << (it == vec.begin() ? "" : ", ") << *it; } return os << "}"; } template ostream& operator<<(ostream& os, const vector >& vec) { os << "{\n"; foreach (it, vec) { os << (it == vec.begin() ? " " : "\n ") << *it; } return os << "\n}"; } template ostream& operator<<(ostream& os, const vector > >& vec) { os << "{\n"; foreach (it, vec) { os << (it == vec.begin() ? "" : "\n") << it - vec.begin() << ": " << *it; } return os << "\n}"; } template ostream& operator<<(ostream& os, const set& se) { os << "{"; foreach (it, se) { os << (it == se.begin() ? "" : ", ") << *it; } return os << "}"; } template ostream& operator<<(ostream& os, const multiset& ms) { os << "{"; foreach (it, ms) { os << (it == ms.begin() ? "" : ", ") << *it; } return os << "}"; } template ostream& operator<<(ostream& os, const map& ma) { os << "{"; foreach (it, ma) { os << (it == ma.begin() ? "" : ", ") << *it; } return os << "}"; } template ostream& operator<<(ostream& os, priority_queue pq) { os << "{"; while (!pq.empty()) { os << pq.top(), pq.pop(); if (!pq.empty()) os << ", "; } return os << "}"; } template ostream& operator<<(ostream& os, const pair& p) { const auto& [a, b] = p; return os << "(" << a << ", " << b << ")"; } template ostream& operator<<(ostream& os, const tuple& t) { const auto& [a, b, c] = t; return os << "(" << a << ", " << b << ", " << c << ")"; } template ostream& operator<<(ostream& os, const tuple& t) { const auto& [a, b, c, d] = t; return os << "(" << a << ", " << b << ", " << c << ", " << d << ")"; } void dump_func() {} template void dump_func(const A& a, const B&... b) { cout << a << (sizeof...(b) ? ", " : "\n"); dump_func(b...); } #ifdef _DEBUG #define dump(...) cout << "[" << (#__VA_ARGS__) << "]: ", dump_func(__VA_ARGS__) #else #define dump(...) #endif #endif