diff --git a/1733. Minimum Number of People to Teach b/1733. Minimum Number of People to Teach new file mode 100644 index 0000000..428e9d7 --- /dev/null +++ b/1733. Minimum Number of People to Teach @@ -0,0 +1,31 @@ +class Solution { +public: + int minimumTeachings(int n, vector>& languages, vector>& friendships) { + set need; + for(const auto& p : friendships) { + int u = p[0] - 1, v = p[1] - 1; + bool ok = false; + for (int x : languages[u]) { + for (int y : languages[v]) { + if (x == y) { ok = true; break; } + } + if (ok) break; + } + if (!ok) { need.insert(u); need.insert(v); } + } + + int ans = languages.size() + 1; + for (int i = 1; i <= n; ++i) { + int cnt = 0; + for (int v : need) { + bool found = false; + for (int c : languages[v]) { + if (c == i) { found = true; break; } + } + if (!found) ++cnt; + } + ans = min(ans, cnt); + } + return ans; + } +};