C++, filter friendships, 100%
\nclass Solution {\npublic:\n    int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n        int m=languages.size()
```\nclass Solution {\npublic:\n    int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n        int m=languages.size();\n        vector<vector<bool>> hasLan(m+1,vector<bool>(n+1,false));  //cache for which languages each user known\n        for(int i=1;i<=m;++i) \n            for(auto& lan:languages[i-1]) hasLan[i][lan]=true;\n        \n        filterFriendShips(n,hasLan, friendships); //filter out friendships in which two users already know one common language\n        \n        int minTeach=INT_MAX,lan,teachi,user1,user2;;\n        bool* teached= new bool[m+1];\n        for(lan=1;lan<=n;++lan) {\n            memset(teached,0,(m+1)*sizeof(bool));\n            teachi=0;\n            \n            for(auto& f:friendships) {\n                user1 = f[0],user2 = f[1];\n                if(teached[user1] && teached[user2] ) continue;\n                \n                if(!hasLan[user1][lan] && !teached[user1])  { teachi++; teached[user1]=true; }\n                if(!hasLan[user2][lan] && !teached[user2])  { teachi++; teached[user2]=true; }\n                \n                if(teachi>=minTeach) break;\n            }\n            \n            minTeach=min(minTeach, teachi);\n        }\n        \n        delete[] teached;\n        return minTeach;\n    }\n    \n    void filterFriendShips(int n, vector<vector<bool>>& hasLan,vector<vector<int>>& friendships) {\n        vector<vector<int>> temp;\n        int user1,user2;\n        for(auto&f:friendships) {\n            user1 = f[0], user2 = f[1];\n            \n            bool bAllKnowLan=false;\n            for(int lan=1;lan<=n;++lan) \n                if(hasLan[user1][lan] && hasLan[user2][lan] ) { bAllKnowLan = true; break;}\n            \n            if(!bAllKnowLan)  temp.push_back({user1,user2});\n        }\n\n        friendships = temp;\n    }\n};\n\n```\n
[]