#include using namespace std; using ll = long long; #include using namespace atcoder; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N,M; cin>>N>>M; dsu d(N); vector>> E(M); for(int i=0;i>E[i].second.first>>E[i].second.second>>E[i].first; E[i].second={E[i].second.first-1,E[i].second.second-1}; } sort(E.begin(),E.end()); reverse(E.begin(),E.end()); vector> G(N); int W=-1; for(int i=0;i D(N,1e8); queue Q; Q.push(0); D[0]=0; while(!Q.empty()){ int p=Q.front(); Q.pop(); for(auto v:G[p]){ if(D[v]>D[p]+1){ D[v]=D[p]+1; Q.push(v); } } } cout<