func_code_string: #include <bits/stdc++.h>   using namespace std;   template <typename T>   string tostr(const T& t) {     ostringstream os;     os << t;     return os.str();   }   int adj[110][110];   int adj2[110][110];   int N, M;   set<int> emp[110];   bool are_connected2(int a, int b) {     set<int>::iterator it;     for (it = emp[a].begin(); it != emp[a].end(); ++it) {       int x = *it;       if (emp[b].count(x)) return true;     }     return false;   }   void floyd() {     for (int k = (int)(0); k <= (int)(N - 1); ++k)       for (int i = (int)(0); i <= (int)(N - 1); ++i)         for (int j = (int)(0); j <= (int)(N - 1); ++j) {           if (adj[i][k] == 9999999 || adj[k][j] == 9999999) continue;           adj[i][j] = 1;         }   }   bool are_connected(vector<int>& comp1, vector<int>& comp2) {     for (int i = (int)(0); i <= (int)(comp1.size() - 1); ++i) {       for (int j = (int)(0); j <= (int)(comp2.size() - 1); ++j) {         if (adj[comp1[i]][comp2[j]] != 9999999) return true;       }     }     return false;   }   vector<vector<int> > find_scc() {     floyd();     vector<int> colors = vector<int>(N, -1);     int cur_color = -1;     for (int i = (int)(0); i <= (int)(N - 1); ++i) {       for (int j = (int)(i + 1); j <= (int)(N - 1); ++j) {         if (adj[i][j] != 9999999 && adj[j][i] != 9999999) {           if (colors[i] != -1)             colors[j] = colors[i];           else {             ++cur_color;             colors[i] = colors[j] = cur_color;           }         }       }     }     for (int i = (int)(0); i <= (int)(colors.size() - 1); ++i)       if (colors[i] == -1) colors[i] = ++cur_color;     int ncolors = cur_color + 1;     for (int i = (int)(0); i <= (int)(N - 1); ++i)       for (int j = (int)(0); j <= (int)(N - 1); ++j) adj2[i][j] = 9999999;     vector<vector<int> > comp_list = vector<vector<int> >(ncolors);     for (int i = (int)(0); i <= (int)(ncolors - 1); ++i) {       for (int j = (int)(0); j <= (int)(N - 1); ++j) {         if (colors[j] == i) comp_list[i].push_back(j);       }     }     for (int i = (int)(0); i <= (int)(comp_list.size() - 1); ++i) {       for (int j = (int)(0); j <= (int)(comp_list.size() - 1); ++j) {         if (are_connected(comp_list[i], comp_list[j])) {           adj2[i][j] = 1;         }       }     }     return comp_list;   }   int main() {     cin >> N >> M;     bool nonZero = false;     for (int i = (int)(0); i <= (int)(N - 1); ++i) {       int k;       cin >> k;       for (int j = (int)(0); j <= (int)(k - 1); ++j) {         int a;         cin >> a;         --a;         emp[i].insert(a);         if (a != 0) nonZero = true;       }     }     if (!nonZero) {       cout << N << endl;       return 0;     }     for (int i = (int)(0); i <= (int)(N - 1); ++i)       for (int j = (int)(0); j <= (int)(N - 1); ++j) adj[i][j] = 9999999;     for (int i = (int)(0); i <= (int)(N - 1); ++i) {       for (int j = (int)(i + 1); j <= (int)(N - 1); ++j) {         if (are_connected2(i, j)) {           adj[i][j] = 1;           adj[j][i] = 1;         }       }     }     vector<vector<int> > scc = find_scc();     int ans = (int)scc.size() - 1;     cout << ans;     return 0;   }   