func_code_string: #include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 3) + (x << 1) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   struct node {     int u, v, w, t;   } e[1000005], E[1000005];   int cmp(node a, node b) { return a.w < b.w; }   struct Union_Find_Set {     int top, stk[1000005], siz[1000005], tot, fa[1000005];     void init(int x) {       tot = x;       for (int i = 1; i <= x; i++) fa[i] = i, siz[i] = 1;       return;     }     int find(int x) {       while (x != fa[x]) x = fa[x];       return x;     }     void link(int x, int y) {       int u = find(x), v = find(y);       if (u == v) return;       if (siz[u] < siz[v]) swap(u, v);       tot -= (siz[u] & 1);       tot -= (siz[v] & 1);       siz[u] += siz[v];       fa[v] = u;       tot += (siz[u] & 1);       stk[++top] = v;       return;     }     void cut() {       int x = stk[top], u = find(x);       --top;       tot -= (siz[u] & 1);       siz[u] -= siz[x];       fa[x] = x;       tot += (siz[u] & 1);       tot += (siz[x] & 1);     }   } S;   int n, m, ans[1000005], id[1000005];   void solve(int l, int r, int x, int y) {     if (l > r) return;     int mid = (l + r) >> 1, pre = S.top;     for (int i = l; i <= mid; i++)       if (id[i] < x) S.link(E[i].u, E[i].v);     for (int i = x; i <= y; i++) {       if (e[i].t <= mid) S.link(e[i].u, e[i].v);       if (!S.tot) {         ans[mid] = i;         break;       }     }     while (S.top > pre) S.cut();     if (!ans[mid]) {       for (int i = l; i <= mid; i++)         if (id[i] < x) S.link(E[i].u, E[i].v);       solve(mid + 1, r, x, y);       while (S.top > pre) S.cut();       return;     }     for (int i = l; i <= mid; i++)       if (id[i] < x) S.link(E[i].u, E[i].v);     solve(mid + 1, r, x, ans[mid]);     while (S.top > pre) S.cut();     for (int i = x; i < ans[mid]; i++)       if (e[i].t < l) S.link(e[i].u, e[i].v);     solve(l, mid - 1, ans[mid], y);     while (S.top > pre) S.cut();   }   int main() {     n = read();     m = read();     S.init(n);     for (int i = 1; i <= m; i++) {       e[i].u = read();       e[i].v = read();       e[i].w = read();       e[i].t = i;     }     for (int i = 1; i <= m; i++) E[i] = e[i];     sort(e + 1, e + 1 + m, cmp);     for (int i = 1; i <= m; i++) id[e[i].t] = i;     solve(1, m, 1, m);     for (int i = 1; i <= m; i++) printf( %d n , ans[i] ? e[ans[i]].w : -1);     return 0;   }   