func_code_string: #include <bits/stdc++.h>   using namespace std;   struct E {     int a, b, c;   };   struct unionfind {     vector<int> p, s;     int c;     unionfind(int n) : p(n, -1), s(n, 1), c(n) {}     int find(int a) { return p[a] == -1 ? a : find(p[a]); }     vector<pair<int *, int>> buf;     void save(int &a) { buf.emplace_back(&a, a); }     int snapshot() { return buf.size(); }     void rollback(int w) {       while (buf.size() > w) {         int *a, b;         tie(a, b) = buf.back();         buf.pop_back();         *a = b;       }     }     bool unite(int a, int b) {       a = find(a);       b = find(b);       if (a == b) return false;       if (s[a] < s[b]) swap(a, b);       save(p[b]);       save(s[a]);       p[b] = a;       s[a] += s[b];       return true;     }     bool same(int a, int b) { return find(a) == find(b); }     int sz(int a) { return s[find(a)]; }   };   int main() {     cin.tie(0);     ios::sync_with_stdio(0);     int n, m;     cin >> n >> m;     vector<E> raw(m);     map<int, vector<pair<int, int>>> es;     for (int i = 0; i < m; ++i) {       int a, b, c;       cin >> a >> b >> c;       a--;       b--;       es[c].push_back({a, b});       raw[i] = {a, b, c};     }     map<int, vector<pair<int, vector<int>>>> qs;     int q;     cin >> q;     vector<int> ans(q, 1);     for (int i = 0; i < q; ++i) {       int k;       cin >> k;       vector<int> idx(k);       for (int j = 0; j < k; ++j) {         cin >> idx[j];         idx[j]--;       }       sort(idx.begin(), idx.end(),            [&](int a, int b) { return raw[a].c < raw[b].c; });       for (int j = 0; j < k;) {         vector<int> w;         int r = j;         while (r < k && raw[idx[r]].c == raw[idx[j]].c) {           w.push_back(idx[r++]);         }         qs[raw[idx[j]].c].emplace_back(i, w);         j = r;       }     }     unionfind uf(n);     for (auto kv : es) {       for (auto z : qs[kv.first]) {         int s = uf.snapshot();         for (auto i : z.second) {           if (!uf.unite(raw[i].a, raw[i].b)) {             ans[z.first] = 0;           }         }         uf.rollback(s);       }       for (auto e : kv.second) {         uf.unite(e.first, e.second);       }     }     for (int i = 0; i < q; ++i) {       if (ans[i])         cout <<  YES               <<   n ;       else         cout <<  NO               <<   n ;     }   }   