maximum-path-quality-of-a-graph - Java Solution
\n\n# Code\njava []\nclass Solution {\n    HashMap<Integer,List<int[]>> graph;\n    int result=0;\n    public int maximalPathQuality(int[] values, int[][] edges
\n\n# Code\n```java []\nclass Solution {\n    HashMap<Integer,List<int[]>> graph;\n    int result=0;\n    public int maximalPathQuality(int[] values, int[][] edges, int maxTime) {\n        graph=new HashMap<>();\n        for(int[] i:edges){\n            graph.computeIfAbsent(i[0],k->new ArrayList<>()).add(new int[]{i[1],i[2]});\n            graph.computeIfAbsent(i[1],k->new ArrayList<>()).add(new int[]{i[0],i[2]});\n        }\n        backtrack(values,new int[values.length],0,0,0,maxTime);\n        return result;\n    }\n    private void backtrack(int[] values,int[] visited,int idx,int time,int value,int maxTime){\n        if(time>maxTime){\n            return;\n        }\n        if(visited[idx]==0){\n            value+=values[idx];\n        }\n        if(idx==0){\n            result=Math.max(result,value);\n        }\n        visited[idx]++;\n        for(int[] i:graph.getOrDefault(idx,new ArrayList<>())){\n            backtrack(values,visited,i[0],time+i[1],value,maxTime);\n        }\n        visited[idx]--;\n    }\n}\n```
['Array', 'Backtracking', 'Graph', 'Java']