scala union find
scala []\nobject Solution {\n  import scala.util.chaining._\n  def friendRequests(n: Int, restrictions: Array[Array[Int]], requests: Array[Array[Int]]): Array[B
```scala []\nobject Solution {\n  import scala.util.chaining._\n  def friendRequests(n: Int, restrictions: Array[Array[Int]], requests: Array[Array[Int]]): Array[Boolean] = {\n    val djs = Array.range(0,n)\n    val restrs = Vector.fill(n)(collection.mutable.Set.empty[Int])\n      .tap(rs => restrictions.foreach{a => rs(a.head)+=a.last; rs(a.last)+=a.head})\n    def root(i: Int): Int = if(djs(i)==i) i else root(djs(i)).tap{rc => djs(i) = rc}\n    def join(i:Int,j:Int):Unit =\n      ().tap(_ => restrs(root(i)) ++= restrs(root(j)).map(root))\n        .tap(_ => djs(root(j))=root(i)).tap(_ => root(j))\n    requests.map(_.sorted).map{a =>\n      lazy val (r0,r1) = (root(a.head), root(a.last))\n      (!restrs(r0).contains(r1) && !restrs(r1).contains(r0))\n        .tap(if(_) join(a.head,a.last))\n    }\n  }\n}\n```
['Union Find', 'Graph', 'Scala']