Easy understanding java code (Plain DFS)
\nclass Solution {\n    public int maximalPathQuality(int[] values, int[][] edges, int maxTime) {\n        int n = values.length;\n        int[] res = new int[]
```\nclass Solution {\n    public int maximalPathQuality(int[] values, int[][] edges, int maxTime) {\n        int n = values.length;\n        int[] res = new int[]{Integer.MIN_VALUE};\n        List<List<int[]>> graph = buildGraph(n, edges);\n        Set<Integer> visited = new HashSet<>();\n        visited.add(0);\n        helper(graph, values, 0, 0, maxTime, visited, res);\n        return res[0];\n    }\n    private void helper(List<List<int[]>> graph, int[] values, int curNode, int curTime, int maxTime, Set<Integer> visited, int[] res) {\n        if (curTime > maxTime) {\n            return;\n        }\n        if (curNode == 0) {\n            int tmp = 0;\n            for (int key : visited) {\n                tmp += values[key];\n            }\n            res[0] = Math.max(res[0], tmp);\n        }\n        for (int[] info : graph.get(curNode)) {\n            int neiborNode = info[0];\n            int neiborTimeCost = info[1];\n            boolean flag = visited.add(neiborNode);\n            helper(graph, values, neiborNode, curTime + neiborTimeCost, maxTime, visited, res);\n            if (flag) {\n                visited.remove(neiborNode);\n            }\n        }\n    }\n    private List<List<int[]>> buildGraph(int n, int[][] edges) {\n        List<List<int[]>> graph = new ArrayList<>();\n        for (int i = 0; i < n; i++) {\n            graph.add(new ArrayList<>());\n        }\n        for (int[] e : edges) {\n            graph.get(e[0]).add(new int[]{e[1], e[2]});\n            graph.get(e[1]).add(new int[]{e[0], e[2]});\n        }\n        return graph;\n    }\n}\n```
[]