-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1733.py
More file actions
26 lines (24 loc) · 822 Bytes
/
1733.py
File metadata and controls
26 lines (24 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Solution:
def minimumTeachings(
self, n: int, languages: List[List[int]], friendships: List[List[int]]
) -> int:
cncon = set()
for friendship in friendships:
mp = {}
conm = False
for lan in languages[friendship[0] - 1]:
mp[lan] = 1
for lan in languages[friendship[1] - 1]:
if lan in mp:
conm = True
break
if not conm:
cncon.add(friendship[0] - 1)
cncon.add(friendship[1] - 1)
max_cnt = 0
cnt = [0] * (n + 1)
for friendship in cncon:
for lan in languages[friendship]:
cnt[lan] += 1
max_cnt = max(max_cnt, cnt[lan])
return len(cncon) - max_cnt