Reason of int visited and not boolean | DFS | with explanation.
Intuition\n- We need to travel all the possible path\u2019s and if we come back to 0 then check the max score.\n- We wont fall into infinite loop because we are
# Intuition\n- We need to travel all the possible path\u2019s and if we come back to 0 then check the max score.\n- We wont fall into infinite loop because we are reducing the time in every dfs call, if we dont have enough time it wont call other nodes and simply return.\n- We cannot have boolean visited because\n    - suppose 0 - 1 - 2   &&  0 - 3  are the edges connected\n    - In the above scenario 0 1 and 2 will be marked visited after 0 \u2192 2 dfs.\n    - Now 2 goes back to 1 \u2192 0 \u2192 3 (considering we have enough time to cover all nodes in graph)\n        - Now when we track back from 3 \u2192 0 that time 0 will be marked unvisited which is actually not true\n            - It is the 2nd visit of 0\u2019th node.\n        - so we must keep track of visited count.\n\n\n\n# Code\n```\nclass Solution {\n    int ans;\n    int[] values;\n    ArrayList<ArrayList<int[]>> graph;\n    int[] visisted;\n\n    public int maximalPathQuality(int[] vals, int[][] edges, int maxTime) {\n        values = vals;\n        ans = 0;\n        visisted = new int[vals.length];\n\n        graph = new ArrayList<>();\n        for (int i : values) {\n            graph.add(new ArrayList());\n        }\n        for (int[] edge : edges) {\n            int u = edge[0];\n            int v = edge[1];\n            int t = edge[2];\n            graph.get(u).add(new int[] { v, t });\n            graph.get(v).add(new int[] { u, t });\n        }\n        dfs(0, maxTime, 0);\n        return ans;\n    }\n\n    public void dfs(int src, int maxTime, int score) {\n\n        if (visisted[src] == 0) {\n            score += values[src];\n        }\n        if (src == 0) {\n            ans = Math.max(ans, score);\n        }\n        visisted[src]++;\n        for (int[] nbr_time : graph.get(src)) {\n            int nbr = nbr_time[0];\n            int currTime = nbr_time[1];\n            if (maxTime - currTime >= 0) { // this wont let infinite loop as time is reducing\n                dfs(nbr, maxTime - currTime, score);\n            }\n        }\n        visisted[src]--;\n    }\n}\n```
['Depth-First Search', 'Java']