func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 500010;   int n, m;   struct edge {     int a, b, c, t;   } e[N];   inline bool operator<(const edge &a, const edge &b) { return a.c < b.c; }   struct union_find {     int f[N], h[N], sz[N], cnt;     struct oper {       int x, fx, hx, szx, tc;     } op[N * 2];     int l;     void init() {       l = 0, cnt = n;       for (int i = 1; i <= n; i++) f[i] = i, h[i] = 0, sz[i] = 1;     }     int find(int x) { return f[x] == x ? x : find(f[x]); }     void rewind(int t) {       for (int i = l; i >= t + 1; i--) {         int x = op[i].x;         f[x] = op[i].fx, h[x] = op[i].hx;         sz[x] = op[i].szx;         cnt = op[i].tc;       }       l = t;     }     void merge(int a, int b) {       int fa = find(a), fb = find(b);       if (fa != fb) {         if (h[fa] > h[fb]) swap(fa, fb);         op[++l] = (oper){fa, f[fa], h[fa], sz[fa], cnt},         op[++l] = (oper){fb, f[fb], h[fb], sz[fb], cnt};         if (sz[fa] && sz[fb]) cnt -= 2;         f[fa] = fb;         h[fb] = max(h[fb], h[fa] + 1);         sz[fb] ^= sz[fa];       }     }   } T;   int j = 1, ans[N];   vector<int> ed[N << 2];   namespace seg {   int a, b, c;   void add(int x, int l, int r) {     if (a <= l && r <= b)       ed[x].push_back(c);     else {       if (a <= ((l + r) >> 1)) add((x << 1), l, ((l + r) >> 1));       if (b > ((l + r) >> 1)) add(((x << 1) | 1), ((l + r) >> 1) + 1, r);     }   }   }  // namespace seg   void solve(int x, int l, int r) {     int len = ed[x].size(), l0 = T.l;     for (int i = 0; i < len; i++) T.merge(e[ed[x][i]].a, e[ed[x][i]].b);     if (l == r) {       ans[l] = ans[l + 1];       while (j <= m && T.cnt) {         if (e[j].t <= l) {           seg::a = e[j].t, seg::b = l - 1, seg::c = j;           if (seg::a <= seg::b) seg::add(1, 1, m);           T.merge(e[j].a, e[j].b);           ans[l] = e[j].c;         }         j++;       }       if (T.cnt) ans[l] = -1;     } else       solve(((x << 1) | 1), ((l + r) >> 1) + 1, r),           solve((x << 1), l, ((l + r) >> 1));     T.rewind(l0);   }   int main() {     scanf( %d%d , &n, &m);     T.init();     for (int i = 1; i <= m; i++)       scanf( %d%d%d , &e[i].a, &e[i].b, &e[i].c), e[i].t = i;     sort(e + 1, e + m + 1);     solve(1, 1, m);     for (int i = 1; i <= m; i++) printf( %d n , ans[i]);     return 0;   }   