3
bool checkinvalid(int a, int b,4
vector<vector<int>> &languages) { // helper func., checks if a5
// and b can communicate or not8
for (int i = 0; i < languages[a].size(); i++) {9
if (find(languages[b].begin(), languages[b].end(), languages[a][i]) != languages[b].end())15
int minimumTeachings(int n, vector<vector<int>> &languages, vector<vector<int>> &friendships) {16
int m = languages.size();17
vector<vector<int>> g(m + 1, vector<int>(0)); // graph to store adjacency list with people as18
// nodes & friendships as edges20
for (int i = 0; i < friendships.size(); i++) {21
g[friendships[i][0]].push_back(friendships[i][1]);22
g[friendships[i][1]].push_back(friendships[i][0]);25
vector<int> voters(m + 1, 0); // to store people who cant communicate with atleast a friend27
for (int i = 1; i < m + 1; i++) {28
for (int j = 0; j < g[i].size(); j++) {29
if (checkinvalid(i, g[i][j], languages)) { // ith can vote36
unordered_map<int, int> mappy; // language -> votes39
for (int i = 1; i < m + 1; i++) {41
for (int j : languages[i - 1]) {44
if (maxvotes < mappy[j]) {50
return voterscount - maxvotes; // # who need to be taught the language