func_code_string: #include <bits/stdc++.h>   using namespace std;   map<pair<int, int>, int> mmp;   int n, m, L[1000010], R[1000010], V[1000010], Head[1000010], Next[1000010],       Go[1000010], Val[1000010], Cnt = 0, tmp[1000010], Dep[1000010], fa[200010],                                  Fa[200010][20], Len[200010][20];   int Ans[1000010];   int qwq = 1e9;   bool used[1000010];   int getf(int first) {     return fa[first] == first ? first : fa[first] = getf(fa[first]);   }   bool cmp(int first, int second) { return V[first] < V[second]; }   struct hp {     int Rt[5000010], L[5000010], R[5000010], Val[5000010], Dis[5000010], Cnt;     hp() { Cnt = 0; }     int newnode(int first) {       Val[++Cnt] = first, L[Cnt] = R[Cnt] = 0;       return Cnt;     }     int merge(int first, int second) {       if (!first || !second) return first + second;       if (Val[first] > Val[second]) swap(first, second);       R[first] = merge(R[first], second);       if (Dis[L[first]] < Dis[R[first]]) swap(L[first], R[first]);       Dis[first] = Dis[R[first]] + 1;       return first;     }     void delrt(int first) { Rt[first] = merge(L[Rt[first]], R[Rt[first]]); }     void add(int first, int v) {       Rt[first * 2] = merge(Rt[first * 2], newnode(v));       while (Rt[first * 2] && Rt[first * 2 + 1] &&              Val[Rt[first * 2]] == Val[Rt[first * 2 + 1]])         delrt(first * 2), delrt(first * 2 + 1);     }     void del(int first, int v) {       Rt[first * 2 + 1] = merge(Rt[first * 2 + 1], newnode(v));       while (Rt[first * 2] && Rt[first * 2 + 1] &&              Val[Rt[first * 2]] == Val[Rt[first * 2 + 1]])         delrt(first * 2), delrt(first * 2 + 1);     }     int ask(int first) { return Val[Rt[first * 2]]; }     void mm(int first, int second) {       Rt[first * 2] = merge(Rt[first * 2], Rt[second * 2]);       Rt[first * 2 + 1] = merge(Rt[first * 2 + 1], Rt[second * 2 + 1]);       while (Rt[first * 2] && Rt[first * 2 + 1] &&              Val[Rt[first * 2]] == Val[Rt[first * 2 + 1]])         delrt(first * 2), delrt(first * 2 + 1);     }   } pvp;   void addedge(int first, int second, int z) {     Go[++Cnt] = second;     Next[Cnt] = Head[first];     Head[first] = Cnt;     Val[Cnt] = z;   }   void DFS(int first, int f, int fv, int d) {     Fa[first][0] = f, Len[first][0] = fv, Dep[first] = d;     for (int T = Head[first]; T; T = Next[T])       if (Go[T] != f) DFS(Go[T], first, Val[T], d + 1);   }   int Solve(int first, int second) {     if (Dep[first] < Dep[second]) swap(first, second);     int mx = 0, det = Dep[first] - Dep[second];     for (int i = 19; i >= 0; i--)       if (det >> i & 1) mx = max(mx, Len[first][i]), first = Fa[first][i];     if (first == second) return mx;     for (int i = 19; i >= 0; i--)       if (Fa[first][i] != Fa[second][i])         mx = max(mx, max(Len[first][i], Len[second][i])), first = Fa[first][i],         second = Fa[second][i];     return max(mx, max(Len[first][0], Len[second][0]));   }   int getlca(int first, int second) {     if (Dep[first] < Dep[second]) swap(first, second);     int mx = 0, det = Dep[first] - Dep[second];     for (int i = 19; i >= 0; i--)       if (det >> i & 1) mx = max(mx, Len[first][i]), first = Fa[first][i];     if (first == second) return first;     for (int i = 19; i >= 0; i--)       if (Fa[first][i] != Fa[second][i])         mx = max(mx, max(Len[first][i], Len[second][i])), first = Fa[first][i],         second = Fa[second][i];     return Fa[first][0];   }   void Do(int first, int f) {     for (int T = Head[first]; T; T = Next[T])       if (Go[T] != f) {         Do(Go[T], first);         pvp.mm(first, Go[T]);       }     if (f && pvp.Rt[first * 2])       Ans[mmp[pair<int, int>(first, f)]] = pvp.ask(first);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &L[i], &R[i], &V[i]);       tmp[i] = i, mmp[pair<int, int>(L[i], R[i])] = i,       mmp[pair<int, int>(R[i], L[i])] = i;     }     for (int i = 1; i <= n; i++) fa[i] = i;     sort(tmp + 1, tmp + m + 1, cmp);     for (int i = 1; i <= m; i++) {       int a = L[tmp[i]], b = R[tmp[i]], c = V[tmp[i]];       if (getf(a) != getf(b))         addedge(a, b, c), addedge(b, a, c), fa[getf(a)] = getf(b),                                             used[tmp[i]] = 1;     }     DFS(1, 0, 1e9, 1);     for (int i = 0; i < 19; i++)       for (int j = 1; j <= n; j++)         Fa[j][i + 1] = Fa[Fa[j][i]][i],                   Len[j][i + 1] = max(Len[j][i], Len[Fa[j][i]][i]);     for (int i = 1; i <= m; i++)       if (!used[i]) {         int a = L[i], b = R[i], c = V[i];         int g = getlca(a, b);         pvp.add(a, c), pvp.add(b, c), pvp.del(g, c), pvp.del(g, c);       }     for (int i = 1; i <= n; i++) Ans[i] = 1e9;     Do(1, 0);     for (int i = 1; i <= m; i++)       if (!used[i])         printf( %d n , Solve(L[i], R[i]));       else         printf( %d n , Ans[i]);     return 0;   }   