The only Difficulty you might face.
Intuition\nThe only difficulty you might face in this question is on deciding how to maintain the visited state. \n\n# Code\ncpp []\nclass Solution {\npublic:\n
# Intuition\nThe only difficulty you might face in this question is on deciding how to maintain the visited state. \n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxTime) {\n        int n = values.size();\n        int res = values[0];\n        vector<vector<pair<int,int>>> graph(n);\n        for(int i=0;i<edges.size();i++)\n        {\n            graph[edges[i][0]].push_back({edges[i][1], edges[i][2]});\n            graph[edges[i][1]].push_back({edges[i][0], edges[i][2]});\n        }\n        \n        vector<int> visited(n, 0);\n        dfs(graph, values, visited, res, 0, 0, 0, maxTime);\n        return res;\n    }\n    \n    void dfs(vector<vector<pair<int,int>>>& graph, vector<int>& values, vector<int>& visited, int& res, int node, int score, int time, int& maxTime)\n    {\n        if(time > maxTime)\n            return;\n        \n        if(visited[node] == 0)\n            score += values[node];\n        \n        visited[node]++;\n\t\t\n      \n        if(node == 0)\n            res = max(res, score);\n        \n        for(auto it : graph[node])\n        {\n            int neigh = it.first;\n            int newTime = time + it.second;\n            dfs(graph, values, visited, res, neigh, score, newTime, maxTime);\n        }\n        \n        visited[node]--;\n    }\n};\n/*For every path there should be a seperate visited array. This was thing to understand If its being visited for the first time, we add its value to our sum. After we have processed all its neighbours, we then mark the current node as unvisited i.e. we reduce the count of that node from the visited array.*/\n```
['C++']