func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 9;   long long wei[N], p[N], in[N], ans[N], par[N][22], mx[N][22], h[N];   pair<long long, long long> edge[N];   vector<pair<long long, long long> > vec, adj[N];   priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,                  greater<pair<long long, long long> > >       hp[N];   long long FS(long long v) {     if (p[v] < 0) return v;     return p[v] = FS(p[v]);   }   void US(long long u, long long v, long long id) {     long long a = FS(u), b = FS(v);     if (a == b) return;     if (p[a] > p[b]) swap(a, b);     p[a] += p[b];     p[b] = a;     adj[u].push_back({v, id});     adj[v].push_back({u, id});     in[id] = 1;   }   void DFS1(long long u) {     for (pair<long long, long long> v : adj[u])       if (v.first != par[u][0]) {         h[v.first] = h[u] + 1;         par[v.first][0] = u;         mx[v.first][0] = wei[v.second];         for (long long i = 1; i < 22; i++)           par[v.first][i] = par[par[v.first][i - 1]][i - 1];         for (long long i = 1; i < 22; i++)           mx[v.first][i] =               max(mx[v.first][i - 1], mx[par[v.first][i - 1]][i - 1]);         DFS1(v.first);       }   }   pair<long long, long long> LYFT(long long v, long long dis) {     long long maxx = 0;     for (long long i = 21; i >= 0; i--)       if (h[v] - (1 << i) >= dis) maxx = max(maxx, mx[v][i]), v = par[v][i];     return {v, maxx};   }   long long LCA(long long u, long long v) {     if (h[u] > h[v]) swap(u, v);     v = LYFT(v, h[u]).first;     if (u == v) return v;     for (long long i = 21; i >= 0; i--)       if (par[v][i] != par[u][i]) v = par[v][i], u = par[u][i];     return par[u][0];   }   void DFS2(long long u) {     for (pair<long long, long long> v : adj[u])       if (v.first != par[u][0]) {         DFS2(v.first);         if (hp[v.first].size()) ans[v.second] = hp[v.first].top().first - 1;         if (hp[v.first].size() > hp[u].size()) swap(hp[u], hp[v.first]);         while (hp[v.first].size()) {           pair<long long, long long> x = hp[v.first].top();           hp[v.first].pop();           if (x.second < h[u]) hp[u].push(x);         }       }     while (hp[u].size() && hp[u].top().second >= h[u]) hp[u].pop();   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n, m;     cin >> n >> m;     fill(p, p + N, -1);     for (long long i = 0; i < m; i++) {       cin >> edge[i].first >> edge[i].second >> wei[i];       vec.push_back({wei[i], i});     }     sort(vec.begin(), vec.end());     for (long long i = 0; i < m; i++)       US(edge[vec[i].second].first, edge[vec[i].second].second, vec[i].second);     fill(ans, ans + N, -1);     DFS1(1);     for (long long i = 0; i < m; i++)       if (!in[i]) {         long long u = edge[i].first, v = edge[i].second, x = LCA(u, v);         ans[i] = max(LYFT(u, h[x]).second, LYFT(v, h[x]).second) - 1;         hp[u].push({wei[i], h[x]});         hp[v].push({wei[i], h[x]});       }     DFS2(1);     for (long long i = 0; i < m; i++) cout << ans[i] <<    ;     return 0;   }   