1733. Minimum Number of People to Teach
https://leetcode.com/problems/minimum-number-of-people-to-teach
Description
On a social network consisting of m
users and some friendships between users, two users can communicate with each other if they know a common language.
You are given an integer n
, an array languages
, and an array friendships
where:
There are
n
languages numbered1
throughn
,languages[i]
is the set of languages theith
user knows, andfriendships[i] = [ui, vi]
denotes a friendship between the usersui
andvi
.
You can choose one language and teach it to some users so that all friends can communicate with each other. Return the minimum number of users you need to teach.
Note that friendships are not transitive, meaning if x
is a friend of y
and y
is a friend of z
, this doesn't guarantee that x
is a friend of z
. Example 1:
Example 2:
Constraints:
2 <= n <= 500
languages.length == m
1 <= m <= 500
1 <= languages[i].length <= n
1 <= languages[i][j] <= n
1 <= ui < vi <= languages.length
1 <= friendships.length <= 500
All tuples
(ui, vi)
are uniquelanguages[i]
contains only unique values
ac
Last updated