Simple and clean || C++ solution || Beats 96% of run-time
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nit\'s pretty much strai
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nit\'s pretty much straightforward. i am keeping track of frequency of node in my path in the visited array. keeping track of time while doing DFS. calling recursive call if only the time + time of that edge is less than or equal to the limit.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int time = 0;\n    int ans = INT_MIN;\n\n    void solve( int i , int quality , vector<int>& val \n                        , vector<vector<pair<int,int>>>& adj , vector<int>& visited , int maxi )\n    {\n        visited[i]++;\n        if( visited[i] == 1 )\n        {\n            quality = quality + val[i];\n        }\n\n        if( i == 0 )\n        {\n            ans = max( ans , quality );\n        }\n\n        for( auto it : adj[i] )\n        {\n            if( time + it.second <= maxi )\n            {\n                time = time + it.second;\n                solve( it.first , quality , val , adj , visited , maxi );\n                time = time - it.second;\n            }\n        }\n\n        visited[i]--;\n    }\n\n    int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxTime) \n    {\n        int n = values.size();\n        vector<int> visited(n,0);\n\n        vector<vector<pair<int,int>>> adj(n);\n        for(auto e : edges)\n        {\n            adj[e[0]].push_back({e[1],e[2]});\n            adj[e[1]].push_back({e[0],e[2]});\n        }\n\n        solve(0,0,values,adj,visited,maxTime);\n        return ans;\n    }\n};\n```
['C++']