Deep First Search with convient acces to nodes data
Code\n\nclass Solution {\n\n    /**\n     * @param Integer[] $values\n     * @param Integer[][] $edges\n     * @param Integer $maxTime\n     * @return Integer\n
# Code\n```\nclass Solution {\n\n    /**\n     * @param Integer[] $values\n     * @param Integer[][] $edges\n     * @param Integer $maxTime\n     * @return Integer\n     */\n    function maximalPathQuality($values, $edges, $maxTime) {\n        $hash = [];\n\n        foreach($edges as $edge) {\n            [$a, $b, $cost] = $edge;\n            if(!isset($hash[$a])) $hash[$a] = [];\n            if(!isset($hash[$b])) $hash[$b] = [];\n\n            $hash[$a][$b] = $cost;\n            $hash[$b][$a] = $cost;\n        }\n\n        $checked = array_map(fn($val) => false, $values);\n\n        $dfs = function($node, $maxTime, $max, $checked) use ($hash, $values, &$dfs) {\n            if($maxTime < 0) return 0;\n\n            if(!$checked[$node]) {\n                $checked[$node] = true;\n                $max += $values[$node];\n            }\n            \n            $maxes = $node === 0 ? [$max] : [];\n            foreach($hash[$node] as $nbr => $cost) {\n                $maxes[] = $dfs($nbr, $maxTime - $cost, $max, $checked);\n            }\n            return max($maxes);\n        };\n\n        return $dfs(0, $maxTime, 0, $checked);\n    }\n}\n```
['Hash Table', 'Depth-First Search', 'PHP']