Just a runnable solution
Code\n\nimpl Solution {\n    pub fn minimum_teachings(n: i32, languages: Vec<Vec<i32>>, friendships: Vec<Vec<i32>>) -> i32 {\n        fn check(a: &[Vec<i32>], u
# Code\n```\nimpl Solution {\n    pub fn minimum_teachings(n: i32, languages: Vec<Vec<i32>>, friendships: Vec<Vec<i32>>) -> i32 {\n        fn check(a: &[Vec<i32>], u: usize, v: usize, mem: &mut [Vec<i32>]) -> bool {\n            if mem[u][v] != 0 {\n                return mem[u][v] == 1;\n            }\n            for i in 0..a[v].len() {\n                if a[u].binary_search(&a[v][i]).is_ok() {\n                    mem[v][u] = 1;\n                    mem[u][v] = 1;\n                    return true;\n                }\n            }\n            mem[u][v] = -1;\n            mem[v][u] = -1;\n            false\n        }\n\n        let mut languages = languages;\n        let mut mem = vec![vec![0; languages.len() + 1]; languages.len() + 1];\n        let mut ret = languages.len() as i32;\n        for language in languages.iter_mut() {\n            language.sort();\n        }\n        for lang in 1..=n {\n            let mut count = 0;\n            let mut teach = vec![false; languages.len()];\n            for friendship in friendships.iter() {\n                let u = friendship[0] as usize - 1;\n                let v = friendship[1] as usize - 1;\n                if check(&languages, u, v, &mut mem) {\n                    continue;\n                }\n                if languages[u].binary_search(&lang).is_err() {\n                    if !teach[u] {\n                        count += 1;\n                    }\n                    teach[u] = true;\n                }\n                if languages[v].binary_search(&lang).is_err() {\n                    if !teach[v] {\n                        count += 1;\n                    }\n                    teach[v] = true;\n                }\n            }\n            ret = ret.min(count);\n        }\n        ret\n    }\n}\n```
['Rust']