Solution Minimum Number of People to Teach
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public $mem = [];\n\n    public function check($a, $u, $v) {\n        if ($this->mem[$u][$v] != 0) return $this->mem[$u][$v] == 1;\n        for ($i = 0; $i < count($a[$v]); $i++) {\n            if (in_array($a[$v][$i], $a[$u])) {\n                $this->mem[$v][$u] = $this->mem[$u][$v] = 1;\n                return true;\n            }\n        }\n        $this->mem[$u][$v] = $this->mem[$v][$u] = -1;\n        return false;\n    }\n\n    public function minimumTeachings($n, $languages, $friendships) {\n        $m = count($languages);\n        $ret = $m;\n        $this->mem = array_fill(0, $m + 1, array_fill(0, $m + 1, 0));\n\n        for ($i = 0; $i < $m; $i++) {\n            sort($languages[$i]);\n        }\n\n        for ($lang = 1; $lang <= $n; $lang++) {\n            $count = 0;\n            $teach = array_fill(0, $m, false);\n            for ($i = 0; $i < count($friendships); $i++) {\n                $u = $friendships[$i][0] - 1;\n                $v = $friendships[$i][1] - 1;\n                if ($this->check($languages, $u, $v)) continue;\n                if (!in_array($lang, $languages[$u])) {\n                    if (!$teach[$u]) $count++;\n                    $teach[$u] = true;\n                }\n                if (!in_array($lang, $languages[$v])) {\n                    if (!$teach[$v]) $count++;\n                    $teach[$v] = true;\n                }\n            }\n            $ret = min($ret, $count);\n        }\n        return $ret;\n    }\n}\n\n```
['PHP']