Backtracking + DFS Based Approach || C++ Clean Code
Code : \n\nclass Solution {\npublic:\n    int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxTime) {\n        \n        int n = valu
# Code : \n```\nclass Solution {\npublic:\n    int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxTime) {\n        \n        int n = values.size();\n        \n        vector<vector<pair<int, int>>> adj(n);\n        \n        for(auto& edge : edges) {\n            adj[edge[0]].push_back({edge[1], edge[2]});\n            adj[edge[1]].push_back({edge[0], edge[2]});\n        }\n        \n        vector<int> vis(n, 0);     \n        return explorePaths(adj, values, vis, 0, values[0], maxTime);\n    }\n\t\n    int explorePaths(vector<vector<pair<int, int>>>& adj, vector<int>& values, vector<int>& vis, int node, int quality, int time) {\n        \n        int maxQuality = 0;\n        \n        if(node == 0) maxQuality = max(maxQuality, quality);\n        \n        vis[node]++;\n        \n        for(auto& [adjnode, wt] : adj[node]) {\n            if(wt <= time)\n            {\n                int val = quality + (vis[adjnode] ? 0 : values[adjnode]);\n                maxQuality = max(maxQuality, explorePaths(adj, values, vis, adjnode, val, time - wt));\n            }\n        }\n        \n        vis[node]--;\n        \n        return maxQuality;\n    }\n};\n```\n\n***If you find this helpful, do give it a like :)***
['Backtracking', 'Depth-First Search', 'Graph', 'C']