func_code_string: #include <bits/stdc++.h>   using namespace std;   int read() {     int v = 0, f = 1;     char c = getchar();     while (c < 48 || 57 < c) {       if (c ==  - ) f = -1;       c = getchar();     }     while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();     return v * f;   }   const int N = 5e5 + 100, INF = 2e9;   int val[N], a[N], b[N], n, m;   set<pair<int, int> > S;   struct node {     node *ch[2], *fa;     int sum, a, maxID, id;     bool rev;     node() {       ch[0] = ch[1] = fa = this;       sum = a = maxID = id = rev = 0;     }     node(int _a, int _id);   };   node *null = new node;   node *pool[N];   node ::node(int _a, int _id) {     ch[0] = ch[1] = fa = null;     sum = _a;     a = _a;     maxID = _id;     id = _id;     rev = 0;   }   bool isRoot(node *u) { return (u->fa->ch[0] != u) && (u->fa->ch[1] != u); }   bool cmp(int x, int y) { return val[x] < val[y]; }   void up(node *u) {     u->sum = u->ch[0]->sum + u->ch[1]->sum + u->a;     int t[3] = {u->ch[0]->maxID, u->ch[1]->maxID, u->id};     sort(t, t + 3, cmp);     u->maxID = t[2];   }   void putRev(node *u) {     if (u == null) return;     swap(u->ch[0], u->ch[1]);     u->rev ^= 1;   }   void dn(node *u) {     if (u->rev) {       putRev(u->ch[0]);       putRev(u->ch[1]);       u->rev = 0;     }   }   void rotate(node *u) {     node *v = u->fa;     bool w = u == v->ch[0];     if (!isRoot(v))       if (v->fa->ch[0] == v)         v->fa->ch[0] = u;       else         v->fa->ch[1] = u;     u->fa = v->fa;     v->ch[!w] = u->ch[w];     u->ch[w]->fa = v;     u->ch[w] = v;     v->fa = u;     up(v);     up(u);   }   void splay(node *u) {     static node *stk[N];     int top = 1;     stk[1] = u;     for (node *i = u; !isRoot(i); i = i->fa) stk[++top] = i->fa;     for (int i = top; i >= 1; i--) dn(stk[i]);     for (node *i; i = u->fa, !isRoot(u); rotate(u))       if (!isRoot(i)) rotate(u == i->ch[0] ^ i == i->fa->ch[0] ? u : i);   }   void access(node *u) {     for (node *t = null; u != null; t = u, u = u->fa) {       splay(u);       u->a -= t->sum;       u->a += u->ch[1]->sum;       u->ch[1] = t;       up(u);     }   }   void makeRoot(node *u) {     access(u);     splay(u);     putRev(u);   }   void link(node *u, node *v) {     makeRoot(v);     access(u);     splay(u);     u->a += v->sum;     u->sum += v->sum;     v->fa = u;   }   void cut(node *u, node *v) {     makeRoot(u);     access(v);     splay(v);     v->ch[0] = null;     up(v);     u->fa = null;   }   node *getRoot(node *u) {     access(u);     splay(u);     while (u->ch[0] != null) u = u->ch[0];     return u;   }   int querySize(node *u) {     access(u);     splay(u);     return u->sum;   }   bool queryOdd(int u) {     cut(pool[n + u], pool[a[u]]);     bool re = querySize(pool[a[u]]) & 1;     link(pool[n + u], pool[a[u]]);     return re;   }   int main() {     n = read(), m = read();     if (n & 1) {       while (m--) puts( -1 );       return 0;     }     for (int i = 1; i <= n; i++) pool[i] = new node(1, 0);     int num = n;     for (int i = 1; i <= m; i++) {       a[i] = read(), b[i] = read(), val[i] = read();       node *u = pool[a[i]], *v = pool[b[i]];       if (getRoot(u) != getRoot(v)) {         int sizU = querySize(u), sizV = querySize(v);         pool[n + i] = new node(0, i);         link(pool[n + i], u);         link(pool[n + i], v);         S.insert(make_pair(-val[i], i));         if ((sizU & 1) && (sizV & 1)) num -= 2;       } else {         makeRoot(u);         access(v);         splay(v);         int t = v->maxID;         if (val[i] < val[t]) {           pool[n + i] = new node(0, i);           S.erase(make_pair(-val[t], t));           cut(pool[n + t], pool[a[t]]);           cut(pool[n + t], pool[b[t]]);           S.insert(make_pair(-val[i], i));           link(pool[n + i], pool[a[i]]);           link(pool[n + i], pool[b[i]]);         }       }       if (num)         puts( -1 );       else {         while (1) {           int t = (*S.begin()).second;           if (!queryOdd(t)) {             cut(pool[n + t], pool[a[t]]);             cut(pool[n + t], pool[b[t]]);             S.erase(S.begin());           } else {             printf( %d n , val[t]);             break;           }         }       }     }   }   