Solution
C++ []\nclass Solution {\nprivate:\n    bool intersects(vector<int>& a, vector<int>& b, vector<bool>& vis){\n        for(int elem: a){\n            vis[elem] = 
```C++ []\nclass Solution {\nprivate:\n    bool intersects(vector<int>& a, vector<int>& b, vector<bool>& vis){\n        for(int elem: a){\n            vis[elem] = true;\n        }\n\n        bool intersectionFound = false;\n        for(int elem: b){\n            if(vis[elem]){\n                intersectionFound = true;\n                break;\n            }\n        }\n\n        for(int elem: a){\n            vis[elem] = false;\n        }\n\n        return intersectionFound;\n    }\n\npublic:\n    int minimumTeachings(int L, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n        const int U = languages.size();\n        const int F = friendships.size();\n\n        vector<bool> isGood(U + 1, true);\n        vector<bool> tempVis(L + 1, false);\n        for(const vector<int>& V: friendships){\n            int a = V[0];\n            int b = V[1];\n            if(!intersects(languages[a - 1], languages[b - 1], tempVis)){\n                isGood[a] = false;\n                isGood[b] = false;\n            }\n        }\n\n        int badUsers = 0;\n        int maxCount = 0;\n        unordered_map<int, int> count;\n        for(int user = 1; user <= U; ++user){\n            if(!isGood[user]){\n                badUsers += 1;\n                for(int language: languages[user - 1]){\n                    count[language] += 1;\n                    maxCount = max(maxCount, count[language]);\n                }\n            }\n        }\n\n        return badUsers - maxCount;\n    }\n};\n```\n\n```Python3 []\nclass Solution:\n    def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int: \n        languages: List[Set[int]] = [set(language) for language in languages] # O(m*n)\n        without_contact: Set[int] = set()\n\n        FIRST_FRIEND: int = 0\n        SECOND_FRIEND: int = 1\n\n        friendship: List[int]\n        for friendship in friendships: # O(n)\n            friend1: int = friendship[FIRST_FRIEND]\n            friend2: int = friendship[SECOND_FRIEND]\n\n            if not languages[friend1-1].intersection(languages[friend2-1]): # O(m)\n                without_contact.add(friend1-1)\n                without_contact.add(friend2-1)\n\n        languages_spoken: List[int] = []\n\n        person: int\n        for person in without_contact: # O(m)\n            languages_spoken.extend(languages[person])\n\n        most_common: int = max(Counter(languages_spoken).values(), default=0) # O(n)\n\n        return len(without_contact) - most_common\n```\n\n```Java []\nimport java.util.ArrayList;\nimport java.util.HashSet;\nimport java.util.List;\nimport java.util.Set;\n\npublic class Solution {\n    public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n        int m = languages.length;\n        boolean[][] speak = new boolean[m + 1][n + 1];\n        boolean[][] teach = new boolean[m + 1][n + 1];\n        for (int user = 0; user < m; user++) {\n            int[] userLanguages = languages[user];\n            for (int userLanguage : userLanguages) {\n                speak[user + 1][userLanguage] = true;\n            }\n        }\n        List<int[]> listToTeach = new ArrayList<>();\n        for (int[] friend : friendships) {\n            int userA = friend[0];\n            int userB = friend[1];\n            boolean hasCommonLanguage = false;\n            for (int language = 1; language <= n; language++) {\n                if (speak[userA][language] && speak[userB][language]) {\n                    hasCommonLanguage = true;\n                    break;\n                }\n            }\n            if (!hasCommonLanguage) {\n                for (int language = 1; language <= n; language++) {\n                    if (!speak[userA][language]) {\n                        teach[userA][language] = true;\n                    }\n                    if (!speak[userB][language]) {\n                        teach[userB][language] = true;\n                    }\n                }\n                listToTeach.add(friend);\n            }\n        }\n        int minLanguage = Integer.MAX_VALUE;\n        int languageToTeach = 0;\n        for (int language = 1; language <= n; language++) {\n            int count = 0;\n            for (int user = 1; user <= m; user++) {\n                if (teach[user][language]) {\n                    count++;\n                }\n            }\n            if (count < minLanguage) {\n                minLanguage = count;\n                languageToTeach = language;\n            }\n        }\n        Set<Integer> setToTeach = new HashSet<>();\n        for (int[] friend : listToTeach) {\n            int userA = friend[0];\n            int userB = friend[1];\n            if (!speak[userA][languageToTeach]) {\n                setToTeach.add(userA);\n            }\n            if (!speak[userB][languageToTeach]) {\n                setToTeach.add(userB);\n            }\n        }\n        return setToTeach.size();\n    }\n}\n```\n
['C++', 'Java', 'Python3']