func_code_string: #include <bits/stdc++.h>   using namespace std;   void add(int& a, int b) {     a += b;     a = min(a, 100000000);   }   const int MX = 300005;   int root[MX];   bool is_left[MX];   vector<int> nodes[MX];   int left_size[MX], right_size[MX];   int ans = 0;   char s[MX];   vector<int> comps[MX];   int main() {     int n, k;     ignore = scanf( %d %d , &n, &k);     ignore = scanf(  %s , s + 1);     for (int i = 1; i <= k; i++) {       int c;       ignore = scanf(  %d , &c);       while (c--) {         int x;         ignore = scanf( %d , &x);         comps[x].push_back(i);       }     }     for (int i = 1; i <= k; i++) {       root[i] = i;       is_left[i] = false;       nodes[i].push_back(i);       right_size[i] = 1;     }     for (int i = 1; i <= n; i++) {       if (comps[i].size() == 1) {         int x = comps[i][0];         ans -= min(left_size[root[x]], right_size[root[x]]);         if (s[i] ==  0 ) {           if (is_left[x]) {             add(right_size[root[x]], MX);           } else {             add(left_size[root[x]], MX);           }         } else {           if (is_left[x]) {             add(left_size[root[x]], MX);           } else {             add(right_size[root[x]], MX);           }         }         ans += min(left_size[root[x]], right_size[root[x]]);       } else if (comps[i].size() == 2) {         int x = comps[i][0], y = comps[i][1];         if (root[x] != root[y]) {           ans -= min(left_size[root[x]], right_size[root[x]]);           ans -= min(left_size[root[y]], right_size[root[y]]);           if (nodes[root[x]].size() > nodes[root[y]].size()) {             swap(x, y);           }           if ((is_left[x] == is_left[y]) != (s[i] ==  1 )) {             for (int v : nodes[root[x]]) is_left[v] = !is_left[v];             swap(left_size[root[x]], right_size[root[x]]);           }           add(left_size[root[y]], left_size[root[x]]);           add(right_size[root[y]], right_size[root[x]]);           for (int v : nodes[root[x]]) {             nodes[root[y]].push_back(v);             root[v] = root[y];           }           ans += min(left_size[root[x]], right_size[root[x]]);         }       }       printf( %d n , ans);     }   }   