#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) #define srep(i,s,t) for (int i = s; i < (t); ++i) #define dsrep(i,t,s) for(int i = (t)-1; i >= (s); --i) #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define isin(x,l,r) ((l) <= (x) && (x) < (r)) int dx4[4]={1,0,-1,0}; int dy4[4]={0,-1,0,1}; using ll = long long; using uint = unsigned; using ull = unsigned long long; using P = pair; const ll LINF = 1001002003004005006ll; const int INF = 1001001001; const ll mod = 998244353; //////////////////////////////////////////// int n, m; vector

g[100005]; struct edge { int now, front, we, co; bool operator< (edge edge2) const { if(this->we == edge2.we) { return this->co > edge2.co; } else { return this->we < edge2.we; } } }; P dijkstra(int s, int goal) { priority_queue que; vector d(n, -1); que.push(edge{s, -1, INF, 0}); while (!que.empty()) { edge e = que.top(); que.pop(); if(d[e.now] > e.we) continue; if(e.now == goal) return {e.we, e.co}; for(int i = 0; i < g[e.now].size(); i++) { auto [v, w] = g[e.now][i]; // cout << d[e.now] << " " << e.now << " " << e.front << " " << e.we << " " << e.co << endl; if(d[v] < min(e.we, w)) { d[v] = min(e.we, w); que.push(edge{v, e.now, d[v], e.co + 1}); } } } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> m; int a, b, c; rep(i, m) { cin >> a >> b >> c; a--; b--; g[a].push_back(P(b, c)); g[b].push_back(P(a, c)); } auto [we, co] = dijkstra(n - 1, 0); cout << we << " " << co << endl; }