C++
\nclass Solution {\npublic:\n    bool same(int a, int b, vector<vector<int>>& l){\n        int i = 0, y = 0;\n        while (i < l[a].size() && y < l[b].size())
```\nclass Solution {\npublic:\n    bool same(int a, int b, vector<vector<int>>& l){\n        int i = 0, y = 0;\n        while (i < l[a].size() && y < l[b].size()){\n            if (l[a][i] == l[b][y]) return true;\n            else if (l[a][i] < l[b][y]) ++i;\n            else ++y;\n        }\n        return false;\n    }\n    int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n        for (auto& v : languages) sort(v.begin(), v.end());\n        vector<vector<int>> g(languages.size() + 1);\n        for (auto& v : friendships) g[v[0]].push_back(v[1]);\n        int ans = INT_MAX;\n        for (int i = 1; i <= n; ++i){\n            vector<bool> knowsNewLan(languages.size() + 1);\n            int sum = 0;\n            for (int z = 0; z < languages.size(); ++z)\n                if (binary_search(languages[z].begin(), languages[z].end(), i))\n                    knowsNewLan[z + 1] = true;\n            for (int z = 1; z < g.size(); ++z){\n                for (auto& e : g[z]){\n                    if (!same(z - 1, e - 1, languages) && !(knowsNewLan[e] && knowsNewLan[z])){\n                        sum += !knowsNewLan[e];\n                        sum += !knowsNewLan[z];\n                        knowsNewLan[e] = true;\n                        knowsNewLan[z] = true;\n                    }\n                }\n            }\n            ans = min(sum, ans);\n        }\n        return ans;\n    }\n};\n```
[]