func_code_string: #include <bits/stdc++.h>   using namespace std;   const int INF = 1000000007;   int n, m;   int fa[200010];   struct Line {     int u, v, c;   } l[200010];   int p[200010];   bool cmp(int x, int y) { return l[x].c < l[y].c; }   bool intree[200010];   struct Edge {     int v, id, nxt;   } e[400010];   int tot;   int first[200010];   void build(int u, int v, int id) {     e[++tot] = (Edge){v, id, first[u]};     first[u] = tot;     return;   }   int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }   bool merge(int u, int v) {     u = find(u);     v = find(v);     if (u == v) return false;     fa[u] = v;     return true;   }   void init() {     for (int i = 1; i <= n; i++) fa[i] = i;     for (int i = 1; i <= m; i++) p[i] = i;     sort(p + 1, p + m + 1, cmp);     for (int i = 1; i <= m; i++) {       int x = p[i];       if (merge(l[x].u, l[x].v)) {         intree[x] = true;         build(l[x].u, l[x].v, x);         build(l[x].v, l[x].u, x);       }     }     return;   }   const int M = 20;   int f[200010][20];   int g[200010][20];   int h[200010][20];   int dep[200010];   int Id[200010];   void dfs(int u, int lst, int lste) {     Id[u] = lste;     dep[u] = dep[lst] + 1;     f[u][0] = lst;     g[u][0] = l[lste].c;     h[u][0] = INF;     for (int i = 1; i < M; i++) {       f[u][i] = f[f[u][i - 1]][i - 1];       g[u][i] = max(g[u][i - 1], g[f[u][i - 1]][i - 1]);       h[u][i] = INF;     }     for (int i = first[u]; i; i = e[i].nxt)       if (e[i].v != lst) dfs(e[i].v, u, e[i].id);     return;   }   int ans[200010];   void solve(int x) {     int u = l[x].u;     int v = l[x].v;     int c = l[x].c;     ans[x] = 0;     if (dep[u] < dep[v]) swap(u, v);     int need = dep[u] - dep[v], cur = 0;     while (need) {       if (need & 1) {         ans[x] = max(ans[x], g[u][cur]);         h[u][cur] = min(h[u][cur], c);         u = f[u][cur];       }       need >>= 1;       cur++;     }     if (u == v) return;     for (int i = M - 1; i >= 0; i--)       if (f[u][i] != f[v][i]) {         ans[x] = max(ans[x], g[u][i]);         ans[x] = max(ans[x], g[v][i]);         h[u][i] = min(h[u][i], c);         h[v][i] = min(h[v][i], c);         u = f[u][i];         v = f[v][i];       }     ans[x] = max(ans[x], g[u][0]);     ans[x] = max(ans[x], g[v][0]);     h[u][0] = min(h[u][0], c);     h[v][0] = min(h[v][0], c);     return;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) scanf( %d %d %d , &l[i].u, &l[i].v, &l[i].c);     init();     dfs(1, 0, 0);     for (int i = 1; i <= m; i++)       if (!intree[i]) solve(i);     for (int i = M - 1; i > 0; i--)       for (int u = 1; u <= n; u++) {         h[u][i - 1] = min(h[u][i - 1], h[u][i]);         h[f[u][i - 1]][i - 1] = min(h[f[u][i - 1]][i - 1], h[u][i]);       }     for (int u = 2; u <= n; u++) ans[Id[u]] = h[u][0];     for (int i = 1; i <= m; i++)       if (ans[i] != INF)         printf( %d  , ans[i] - 1);       else         printf( -1  );     printf(  n );     return 0;   }   