[Scala] Functional no vars DFS solution
\n  def maximalPathQuality(values: Array[Int], edges: Array[Array[Int]], maxTime: Int): Int = {\n    val adjList = edges.foldLeft(Map.empty[Int, Seq[(Int, Int)]
```\n  def maximalPathQuality(values: Array[Int], edges: Array[Array[Int]], maxTime: Int): Int = {\n    val adjList = edges.foldLeft(Map.empty[Int, Seq[(Int, Int)]].withDefaultValue(Seq.empty)) {\n      case (adj, Array(n1, n2, cost)) =>\n        adj\n          .updated(n1, adj(n1) :+ (n2, cost))\n          .updated(n2, adj(n2) :+ (n1, cost))\n    }\n\n    def dfs(node: Int, visited: Set[Int], quality: Int, budget: Int): Int =\n      adjList(node)\n        .collect {\n          case (next, cost) if (cost <= budget) =>\n            val nextQuality = Option.when(!visited.contains(next))(values(next)).getOrElse(0)\n            dfs(next, visited + next, quality + nextQuality, budget - cost)\n        }\n        .appendedAll(Option.when(node == 0)(quality))\n        .maxOption\n        .getOrElse(0)\n\n    dfs(node = 0, visited = Set(0), quality = values.head, budget = maxTime)\n  }\n```
['Depth-First Search']