func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1000000;   int f[N], sz[N], ak, Ak, n, m, ans[N];   struct data {     int a, b, c, d, e;     data(int a = 0, int b = 0, int c = 0, int d = 0, int e = 0)         : a(a), b(b), c(c), d(d), e(e) {}   } S[N];   struct edge {     int x, y, z, id;     bool operator<(const edge& e) const { return z < e.z; }   } e[N], ee[N];   int find(int x) { return x == f[x] ? x : find(f[x]); }   void me(int x, int y) {     int X = find(x), Y = find(y);     if (X == Y) return;     S[Ak++] = data(X, Y, sz[X], sz[Y], ak);     if (sz[X] & 1 & sz[Y]) ak -= 2;     if (sz[X] > sz[Y]) swap(X, Y);     f[X] = Y;     sz[Y] += sz[X];   }   void pop(int tt) {     while (Ak > tt) {       data haha = S[--Ak];       ak = haha.e;       f[haha.a] = haha.a;       f[haha.b] = haha.b;       sz[haha.a] = haha.c;       sz[haha.b] = haha.d;     }   }   void solve(int l, int r, int x, int y) {     if (x > y) return;     if (l == r) {       for (int i = x; i <= y; i++) ans[i] = l;       return;     }     int mid = (l + r) >> 1, t = y + 1, tt = Ak;     for (int i = l; i <= mid; i++)       if (ee[i].id < x) me(ee[i].x, ee[i].y);     for (int i = x; i <= y; i++) {       if (e[i].z <= mid) me(e[i].x, e[i].y);       if (ak == 0) {         t = i;         break;       }     }     pop(tt);     for (int i = x; i < t; i++)       if (e[i].z < l) me(e[i].x, e[i].y);     solve(l, mid, t, y);     pop(tt);     for (int i = l; i <= mid; i++)       if (ee[i].id < x) me(ee[i].x, ee[i].y);     solve(mid + 1, r, x, t - 1);     pop(tt);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) f[i] = i, sz[i] = 1;     ak = n;     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &e[i].x, &e[i].y, &e[i].z);       e[i].id = i;       ee[i] = e[i];     }     sort(ee + 1, ee + 1 + m);     for (int i = 1; i <= m; i++) e[ee[i].id].z = i;     solve(1, m + 1, 1, m);     ee[m + 1].z = -1;     for (int i = 1; i <= m; i++) printf( %d n , ee[ans[i]].z);     return 0;   }   