Skip to content

Commit 94e32b9

Browse files
authored
Create 1733. Minimum Number of People to Teach (#881)
2 parents 1c4b4ce + ed67cb6 commit 94e32b9

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Solution {
2+
public:
3+
int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {
4+
set<int> need;
5+
for(const auto& p : friendships) {
6+
int u = p[0] - 1, v = p[1] - 1;
7+
bool ok = false;
8+
for (int x : languages[u]) {
9+
for (int y : languages[v]) {
10+
if (x == y) { ok = true; break; }
11+
}
12+
if (ok) break;
13+
}
14+
if (!ok) { need.insert(u); need.insert(v); }
15+
}
16+
17+
int ans = languages.size() + 1;
18+
for (int i = 1; i <= n; ++i) {
19+
int cnt = 0;
20+
for (int v : need) {
21+
bool found = false;
22+
for (int c : languages[v]) {
23+
if (c == i) { found = true; break; }
24+
}
25+
if (!found) ++cnt;
26+
}
27+
ans = min(ans, cnt);
28+
}
29+
return ans;
30+
}
31+
};

0 commit comments

Comments
 (0)