scala DisjointSet/UnionFind
scala\nobject Solution {\n  def minMalwareSpread(graph: Array[Array[Int]], initial: Array[Int]): Int =\n    import scala.util.chaining._\n    val initialSet = i
```scala\nobject Solution {\n  def minMalwareSpread(graph: Array[Array[Int]], initial: Array[Int]): Int =\n    import scala.util.chaining._\n    val initialSet = initial.to(collection.immutable.BitSet)\n    val xMap = graph.zipWithIndex.flatMap{case (a,i) => a.zipWithIndex.collect{\n      case (v,j) if i!=j && v!=0 => List((i,j),(j,i))\n    }}.flatten.distinct.groupMap(_._1)(_._2)\n    initial.iterator.map{ node =>\n      val djs = graph.indices.to(Array)\n      def root(i: Int): Int = if(i == djs(i)) i else root(djs(i)).tap(djs(i) = _)\n      def join(i: Int)(j: Int): Int = \n        if(initialSet.contains(root(j))) root(j).tap(djs(root(i)) = _)\n        else root(i).tap(djs(root(j)) = _)\n      xMap.iterator.filter(_._1 != node).foreach{case (k,v) =>\n        v.filter(k2 => k2>k && k2 != node).foreach(k2 => join(k)(k2))\n      }\n      djs.indices.foreach(root)\n      (djs.zipWithIndex.collect{case (k,i) if k!=node && initialSet.contains(k) => i}.length, node)\n    }.min._2\n}\n```
['Hash Table', 'Union Find', 'Graph', 'Scala']