func_code_string: #include <bits/stdc++.h>   using namespace std;   struct Edge {     int u, v, w;   };   const int N = 500005;   int n, m, q;   Edge edge[N];   vector<int> sorted_edge[N];   vector<pair<int, vector<int>>> query[N];   bool npos[N];   int par[N], rnk[N];   vector<int> rnk_roll, par_roll;   void init() {     for (int i = 1; i <= n; i++) par[i] = i, rnk[i] = 1;   }   int get(int u, bool roll = false) {     if (u == par[u]) return u;     if (roll) return get(par[u], roll);     return par[u] = get(par[u], roll);   }   bool merge(int u, int v, bool roll = false) {     u = get(u, roll), v = get(v, roll);     if (u == v) return false;     if (rnk[u] < rnk[v]) swap(u, v);     if (roll) par_roll.push_back(v);     par[v] = u;     if (rnk[u] == rnk[v]) {       rnk[u]++;       rnk_roll.push_back(u);     }     return true;   }   void rollback() {     for (auto u : rnk_roll) rnk[u]--;     for (auto u : par_roll) par[u] = u;     rnk_roll.clear();     par_roll.clear();   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &edge[i].u, &edge[i].v, &edge[i].w);       sorted_edge[edge[i].w].push_back(i);     }     scanf( %d , &q);     for (int i = 0, k; i < q; i++) {       scanf( %d , &k);       vector<int> elt(k);       for (int i = 0; i < k; i++) scanf( %d , &elt[i]);       sort(elt.begin(), elt.end(),            [](int i, int j) { return edge[i].w < edge[j].w; });       int it = 0, j;       do {         vector<int> ei;         for (j = it; j < k && edge[elt[j]].w == edge[elt[it]].w; j++)           ei.push_back(elt[j]);         query[edge[elt[it]].w].push_back({i, ei});         it = j;       } while (it < k);     }     init();     for (int i = 1; i < N; i++) {       for (auto qq : query[i]) {         int qid = qq.first;         for (auto e : qq.second) {           if (!merge(edge[e].u, edge[e].v, true)) {             npos[qid] = true;             break;           }         }         rollback();       }       for (auto e : sorted_edge[i]) merge(edge[e].u, edge[e].v);     }     for (int i = 0; i < q; i++) {       printf( %s n , npos[i] ?  NO  :  YES );     }     return 0;   }   