func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005, MAXM = 1000005, MAXT = 1 << 18;   struct Edge {     int to, val, next, id;   } edge[MAXM];   struct MST {     int u, v, w, id;   } mst[MAXM];   int ppar[MAXN], head[MAXN], ist[MAXM], dep[MAXN], n, m, tot;   void addedge(int u, int v, int w, int id) {     edge[++tot] = (Edge){v, w, head[u], id};     head[u] = tot;   }   int find(int x) { return x == ppar[x] ? x : ppar[x] = find(ppar[x]); }   void merge(int x, int y) {     x = find(x), y = find(y);     if (x != y) ppar[x] = y;   }   int mmn[MAXT], beg[MAXN], ed[MAXN], ans[MAXM], par[20][MAXN], mx[20][MAXN],       dcnt;   struct Que {     int l, r, id;   };   struct Mod {     int p, w;   };   vector<Que> qr1[MAXN], qr2[MAXN];   vector<Mod> md1[MAXN], md2[MAXN];   void dfs(int u, int fa) {     beg[u] = ++dcnt;     dep[u] = dep[fa] + 1;     for (int i = head[u]; i; i = edge[i].next) {       int v = edge[i].to;       if (v == fa) continue;       dfs(v, u);       qr1[beg[v]].push_back((Que){beg[v], ed[v], edge[i].id});       qr2[ed[v]].push_back((Que){beg[v], ed[v], edge[i].id});       par[0][v] = u;       mx[0][v] = edge[i].val;     }     ed[u] = dcnt;   }   void chk(int &x, int y) { x = x < y ? x : y; }   void cxk(int &x, int y) { x = x > y ? x : y; }   void upd(int x, int w, int l = 1, int r = n, int k = 1) {     if (l == r) {       chk(mmn[k], w);       return;     }     int mid = (l + r) >> 1;     if (x <= mid)       upd(x, w, l, mid, k << 1);     else       upd(x, w, mid + 1, r, k << 1 | 1);     chk(mmn[k], w);   }   int ask(int a, int b, int l = 1, int r = n, int k = 1) {     if (a > r || b < l) return 1E9;     if (a <= l && b >= r) return mmn[k];     int mid = (l + r) >> 1;     return min(ask(a, b, l, mid, k << 1), ask(a, b, mid + 1, r, k << 1 | 1));   }   int calc(int x, int y) {     if (dep[x] > dep[y]) swap(x, y);     int res = 0;     for (int i = 19; ~i; i--)       if (dep[par[i][y]] >= dep[x]) cxk(res, mx[i][y]), y = par[i][y];     if (x == y) return res;     for (int i = 19; ~i; i--)       if (par[i][x] != par[i][y])         cxk(res, mx[i][x]), cxk(res, mx[i][y]), x = par[i][x], y = par[i][y];     return max(res, max(mx[0][x], mx[0][y]));   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       mst[i] = (MST){u, v, w, i};       ans[i] = 1E9;     }     sort(mst + 1, mst + 1 + m,          [&](const MST &a, const MST &b) { return a.w < b.w; });     for (int i = 1; i <= n; i++) ppar[i] = i;     for (int i = 1; i <= m; i++) {       int u = mst[i].u, v = mst[i].v;       if (find(u) != find(v)) {         merge(u, v);         ist[mst[i].id] = 1;         addedge(u, v, mst[i].w, mst[i].id);         addedge(v, u, mst[i].w, mst[i].id);       }     }     for (int i = 0; i < MAXT; i++) mmn[i] = 1E9;     dfs(1, 0);     for (int i = 1; i < 20; i++)       for (int j = 1; j <= n; j++) {         par[i][j] = par[i - 1][par[i - 1][j]];         mx[i][j] = max(mx[i - 1][j], mx[i - 1][par[i - 1][j]]);       }     for (int i = 1; i <= m; i++)       if (!ist[mst[i].id]) {         int u = mst[i].u, v = mst[i].v;         if (beg[u] > beg[v]) swap(u, v);         md1[beg[u]].push_back((Mod){beg[v], mst[i].w});         md2[beg[v]].push_back((Mod){beg[u], mst[i].w});         ans[mst[i].id] = calc(u, v);       }     for (int i = 1; i <= n; i++) {       for (Que q : qr1[i]) chk(ans[q.id], ask(q.l, q.r));       for (Mod d : md1[i]) upd(d.p, d.w);     }     for (int i = 0; i < MAXT; i++) mmn[i] = 1E9;     for (int i = n; i > 0; i--) {       for (Que q : qr2[i]) chk(ans[q.id], ask(q.l, q.r));       for (Mod d : md2[i]) upd(d.p, d.w);     }     for (int i = 1; i <= m; i++) printf( %d n , ans[i]);     return 0;   }   