func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 500010;   struct E {     int u, v, w, I;   } e[N];   int n, m, F[N], T[N], q, k, a[N], A[N], V, d, L[N], C[N];   vector<int> G[N];   bool M(E a, E b) { return a.w < b.w; }   int P(int x) { return x == A[x] ? x : A[x] = P(A[x]); }   void D(int b, int x) {     if (L[x] == b) return;     L[x] = b;     V++;     d += G[x].size();     for (int J = 0; J < G[x].size(); J++) D(b, G[x][J]);   }   bool K(int b, int x) {     V = d = 0;     D(b, x);     return d == 2 * (V - 1);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &e[i].u, &e[i].v, &e[i].w);       e[i].I = i;       F[i] = e[i].u;       T[i] = e[i].v;     }     for (int i = 1; i <= n; i++) A[i] = i;     sort(e + 1, e + m + 1, M);     for (int i = 1; i <= m; i++) {       int o = i;       while (e[o].w == e[i].w && o <= m) {         int u = P(e[o].u), v = P(e[o].v);         F[e[o].I] = u;         T[e[o].I] = v;         C[e[o].I] = u != v;         o++;       }       for (; i < o; i++) A[P(e[i].u)] = P(e[i].v);       i--;     }     scanf( %d , &q);     for (int c = 1; c <= q; c++) {       scanf( %d , &k);       bool Y = 1;       for (int i = 1; i <= k; i++) {         scanf( %d , &a[i]);         if (!C[a[i]]) Y = 0;         G[F[a[i]]].clear();         G[T[a[i]]].clear();       }       for (int i = 1; i <= k; i++)         G[F[a[i]]].push_back(T[a[i]]), G[T[a[i]]].push_back(F[a[i]]);       for (int i = 1; i <= k; i++) {         int x = F[a[i]], y = T[a[i]];         if (L[x] != c) Y &= K(c, x);         if (L[y] != c) Y &= K(c, y);       }       puts(Y ?  YES  :  NO );     }     return 0;   }   