Scala
\nimport scala.collection.immutable.BitSet\nimport scala.util.chaining.scalaUtilChainingOps\n\nobject Solution {\n  def minimumTeachings(n: Int, languages: Arra
```\nimport scala.collection.immutable.BitSet\nimport scala.util.chaining.scalaUtilChainingOps\n\nobject Solution {\n  def minimumTeachings(n: Int, languages: Array[Array[Int]], friendships: Array[Array[Int]]): Int = {\n    languages\n      .map(_.to(BitSet))\n      .pipe { languages =>\n        friendships\n          .filter { case Array(u, v) => (languages(u - 1) & languages(v - 1)).isEmpty }\n          .pipe { friendships =>\n            (1 to n)\n              .view\n              .map { language =>\n                friendships\n                  .view\n                  .flatMap {\n                    case Array(u, v) if languages(u - 1).contains(language) => Iterator(v)\n                    case Array(u, v) if languages(v - 1).contains(language) => Iterator(u)\n                    case Array(u, v) => Iterator(u, v)\n                  }\n                  .toSet\n                  .size\n              }\n              .min\n          }\n      }\n  }\n}\n```
['Scala']