Java DFS solution
Inspiration from @votrubac \'s Plain DFS solution :\nhttps://leetcode.com/problems/maximum-path-quality-of-a-graph/discuss/1563744/Plain-DFS\n\n\nclass Solution
Inspiration from @votrubac \'s Plain DFS solution :\nhttps://leetcode.com/problems/maximum-path-quality-of-a-graph/discuss/1563744/Plain-DFS\n\n```\nclass Solution {\n    \n    int result = 0;\n    List<List<int[]>> graph = new ArrayList<>();\n    int[] values;\n    int[] visited;\n    public int maximalPathQuality(int[] values, int[][] edges, int maxTime) {\n        \n        int vertices = values.length;\n        this.values = values;\n    \n        visited = new int[vertices];\n        \n        \n        for (int i = 0; i < vertices; i++) {\n            graph.add(new ArrayList<>());\n             \n         }\n        \n        for (int i = 0; i < edges.length; i++) {            \n            \n            int v1 = edges[i][0];\n            int v2 = edges[i][1];\n            int w = edges[i][2];            \n            \n            graph.get(v1).add(new int[]{v2, w});\n            graph.get(v2).add(new int[]{v1, w});\n        }\n        \n        dfs(0, visited, 0, maxTime);\n        return result;\n        \n    }\n    \n    public void dfs(int node, int[] visited, int gain, int cost) {\n        \n        if (visited[node] == 0) {\n            gain += values[node];\n        }\n        visited[node]++;\n        \n        if (node == 0) {\n            result = Math.max(result, gain);\n        }\n        \n        for (int[] n : graph.get(node)) {\n            \n            int neighbour = n[0];\n            int w = n[1];\n            \n            if (w <= cost) {\n                \n                dfs(neighbour, visited, gain, cost - w);\n            \n            }\n        }\n        visited[node]--;\n    }\n}\n\n```
[]