Java | DFS
\n\tpublic int maximalPathQuality(int[] values, int[][] edges, int maxTime) {\n        List<List<int[]>> adjList = new ArrayList();\n        for(int i : values)
```\n\tpublic int maximalPathQuality(int[] values, int[][] edges, int maxTime) {\n        List<List<int[]>> adjList = new ArrayList();\n        for(int i : values) {\n            adjList.add(new ArrayList());\n        }\n        \n        for(int edge[] : edges) {\n            adjList.get(edge[0]).add(new int[] {edge[1], edge[2]});\n            adjList.get(edge[1]).add(new int[] {edge[0], edge[2]});\n        }\n        int[] visited = new int[values.length];\n        solve(values, adjList, visited, 0, maxTime, 0, 0);\n        return ans;\n    }\n    int ans;\n    \n    void solve(int[] values, List<List<int[]>> adjList, int[] visited, int node, int maxTime, int currTime, int score) {\n        if(currTime > maxTime) {\n            return;\n        }\n        if(visited[node] == 0) {\n            score += values[node];\n        }\n        \n        if(node == 0) {\n            ans = Math.max(ans, score);\n        }\n        \n        visited[node]++;\n        \n        for(int[] v : adjList.get(node)) {\n            solve(values, adjList, visited, v[0], maxTime, currTime + v[1], score);\n        }\n        \n        visited[node]--;\n    }\n```
['Backtracking', 'Depth-First Search', 'Java']