func_code_string: #include <bits/stdc++.h>   using namespace std;   struct union_find {     vector<int> uf;     vector<int> num_segments;     vector<bool> used;     union_find(int n) {       uf.assign(n, -1);       num_segments.assign(n, 0);       used.assign(n, false);       for (int i = 0; i < n; ++i) {         if (i % 2 == 0) num_segments[i] = 1;       }     }     int find(int i) {       if (uf[i] < 0)         return i;       else         return uf[i] = find(uf[i]);     }     bool merge(int a, int b) {       a = find(a);       b = find(b);       if (a == b) return false;       if (uf[a] <= uf[b]) {         uf[b] = a;         if (uf[a] == uf[b]) {           uf[a]--;         }         num_segments[a] =             min(num_segments[a] + num_segments[b], 2 * (int)uf.size());         used[a] = used[a] || used[b];       } else if (uf[b] < uf[a]) {         uf[a] = b;         num_segments[b] =             min(num_segments[a] + num_segments[b], 2 * (int)uf.size());         used[b] = used[a] || used[b];       }       return true;     }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int N, K;     cin >> N >> K;     string s;     cin >> s;     vector<vector<int>> groups(K);     vector<vector<int>> groups_for_bit(N);     for (int i = 0; i < K; ++i) {       int k;       cin >> k;       groups[i].resize(k);       for (int j = 0; j < k; ++j) {         cin >> groups[i][j];         groups[i][j]--;         groups_for_bit[groups[i][j]].push_back(i);       }     }     auto inverse = [](int x) { return x ^ 1; };     union_find uf(2 * K);     int num_segments = 0;     auto unset = [&](int i) {       if (uf.used[i]) {         uf.used[i] = false;         num_segments -= uf.num_segments[i];         ;       }     };     auto set = [&](int i) {       assert(!uf.used[i]);       uf.used[i] = true;       num_segments += uf.num_segments[i];       ;     };     for (int i = 0; i < N; ++i) {       ;       int g = -1;       if (groups_for_bit[i].size() == 0) {         ;       } else if (groups_for_bit[i].size() == 1) {         g = uf.find(2 * groups_for_bit[i][0]);         int ig = uf.find(inverse(g));         ;         unset(g);         unset(ig);         if (s[i] ==  0 ) {           uf.num_segments[ig] = N * 3;         } else {           uf.num_segments[g] = N * 3;         }       } else {         g = uf.find(2 * groups_for_bit[i][0]);         int h = uf.find(2 * groups_for_bit[i][1]);         int ig = uf.find(inverse(g));         int ih = uf.find(inverse(h));         ;         ;         unset(g);         unset(ig);         unset(h);         unset(ih);         if (s[i] ==  0 ) {           uf.merge(ig, h);           uf.merge(g, ih);         } else {           uf.merge(g, h);           uf.merge(ig, ih);         }       }       if (g >= 0) {         g = uf.find(g);         int ig = uf.find(inverse(g));         set(uf.num_segments[g] <= uf.num_segments[ig] ? g : ig);       }       cout << num_segments <<   n ;     }     return 0;   }   