func_code_string: #include <bits/stdc++.h>   using namespace std;   stack<int> stk;   vector<pair<int, int> > edge[500010];   vector<pair<int, int> > w[500010];   int a[500010], b[500010], c[500010], fa[500010], rk[500010];   bool ans[500010];   int n, m, q;   int Find(int x) {     while (x != fa[x]) x = fa[x];     return x;   }   void Union(int x, int y, bool flag) {     x = Find(x);     y = Find(y);     if (rk[x] < rk[y]) swap(x, y);     if (flag) stk.push(y);     fa[y] = x;     if (rk[x] == rk[y]) ++rk[x];   }   void undo() {     while (!stk.empty()) {       fa[stk.top()] = stk.top();       stk.pop();     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) fa[i] = i;     for (int i = 1; i <= m; ++i) {       scanf( %d%d%d , &a[i], &b[i], &c[i]);       edge[c[i]].push_back(make_pair(a[i], b[i]));     }     scanf( %d , &q);     for (int i = 1; i <= q; ++i) {       int k;       scanf( %d , &k);       while (k--) {         int x;         scanf( %d , &x);         w[c[x]].push_back(make_pair(i, x));       }       ans[i] = true;     }     for (int i = 1; i < 500010; ++i) {       int last = -1;       for (auto &j : w[i])         if (ans[j.first]) {           int o = j.first, k = j.second;           if (o != last) undo(), last = o;           int x = a[k], y = b[k];           if (Find(x) == Find(y))             ans[o] = false;           else             Union(x, y, true);         }       undo();       for (auto &j : edge[i])         if (Find(j.first) != Find(j.second)) Union(j.first, j.second, false);     }     for (int i = 1; i <= q; ++i) puts(ans[i] ?  YES  :  NO );   }   