func_code_string: #include <bits/stdc++.h>   using namespace std;   int p[500005], q[500005], c[500005], f[500005], siz[500005], fx[500005],       sizx[500005], cln[500005 * 2], ans[500005], qu[500005], id[500005];   struct edge {     int u, v, w, nxt, id;   } e[500005];   vector<int> a[500005];   inline int find(int);   void swap(int& a, int& b) {     int t = a;     a = b;     b = t;   }   bool cmpp(int x, int y) { return e[x].w < e[y].w; }   bool cmpq(int x, int y) { return c[x] < c[y]; }   inline int read() {     int x = 0;     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + (c ^ 48);       c = getchar();     }     return x;   }   int main() {     int i, j, n, m, u, v, nm, t, Q, tmp, top = 0, pos = 1, z;     n = read();     m = read();     for (i = 1; i <= m; ++i) {       e[i].u = read();       e[i].v = read();       e[i].w = read();     }     t = read();     for (i = 1; i <= t; ++i) {       nm = read();       for (j = 1; j <= nm; ++j) qu[j] = read();       sort(qu + 1, qu + nm + 1, cmpp);       for (j = 1; j <= nm; ++j) {         if (e[qu[j - 1]].w ^ e[qu[j]].w) {           if (top) a[top][0] = Q;           Q = 0;           id[++top] = i;           c[top] = e[qu[j]].w;           a[top].push_back(0);         }         ++Q;         a[top].push_back(qu[j]);       }     }     a[top][0] = Q;     Q = 0;     for (i = 1; i <= max(top, max(n, m)); ++i) p[i] = q[i] = f[i] = fx[i] = i;     for (i = 1; i <= n; ++i) siz[i] = sizx[i] = 1;     sort(p + 1, p + m + 1, cmpp);     sort(q + 1, q + top + 1, cmpq);     for (i = 1; i <= top; ++i) {       Q = q[i];       tmp = 0;       while (pos <= m && e[p[pos]].w < c[Q]) {         u = find(e[p[pos]].u);         v = find(e[p[pos]].v);         ++pos;         if (u == v) continue;         if (siz[u] < siz[v]) swap(u, v);         cln[++tmp] = v;         f[v] = u;         siz[u] += siz[v];       }       for (j = 1; j <= tmp; ++j) {         fx[cln[j]] = f[cln[j]];         sizx[cln[j]] = siz[cln[j]];       }       nm = a[Q][0];       tmp = 0;       for (j = 1; j <= nm; ++j) {         z = a[Q][j];         u = find(e[z].u);         v = find(e[z].v);         if (u == v) {           ans[id[Q]] = 1;           break;         }         if (siz[u] < siz[v]) swap(u, v);         cln[++tmp] = v;         f[v] = u;         siz[u] += siz[v];       }       for (j = 1; j <= tmp; ++j) {         f[cln[j]] = fx[cln[j]];         siz[cln[j]] = sizx[cln[j]];       }     }     for (i = 1; i <= t; ++i) puts(ans[i] ?  NO  :  YES );     return 0;   }   inline int find(int u) {     while (u != f[u]) u = f[u];     return u;   }   