C++ bitmap with pruning 188 ms
Step 1: If two friends already speak the same language, we don\'t need to include them in the second step.\nStep 2: iterater all languages and check if the user
Step 1: If two friends already speak the same language, we don\'t need to include them in the second step.\nStep 2: iterater all languages and check if the user speaks it. If not, set the bit and increase the user_count.\n\n```\nclass Solution {\npublic:\n    int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n      int users  = languages.size();\n      vector<vector<bool>> lmap(users + 1, vector<bool>(n+1));\n      for(int i = 1; i <= users; ++i)\n        for(auto l : languages[i-1])\n          lmap[i][l] = true;\n      int friends = 0;\n      for(int i = 0, e = friendships.size(); i < e; ++i) {\n        const auto& f = friendships[i];\n        bool has_common_lang = false;\n        for(int k = 1; k <= n && !has_common_lang; ++k)\n          if (lmap[f[0]][k] && lmap[f[1]][k])\n            has_common_lang = true;\n        if (!has_common_lang) \n          friendships[friends++] = f;\n      }\n      int ret = users;\n      auto test_and_set = [&](int i, int l) { if (lmap[i][l]) return 0; lmap[i][l] = true; return 1;};\n      for(int l = 1; l <= n; ++l) {\n        int t = 0;\n        for(int i = 0; i < friends; ++i) {\n         t += test_and_set(friendships[i][0], l);\n         t += test_and_set(friendships[i][1], l);\n        }\n        ret = min(t, ret);\n      }\n      return ret;\n    }\n};\n```
[]