ap
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\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\nvoid dfs(int i,vector<pair<int,int>> adj[],unordered_map<int,int>&vis,int mt,vector<int>&values,int val,int &maxi)\n{\n    if(mt<0)return;\n    if(vis[i]==0)\n    {\n        val+=values[i];\n    }\n    vis[i]++;\n    if(i==0)\n    {\n        maxi=max(maxi,val);\n    }\n    for(auto j:adj[i])\n    {\n        dfs(j.first,adj,vis,mt-j.second,values,val,maxi);\n    }\n    vis[i]--;\n}\n    int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int mt) {\n        int n=values.size();\n        unordered_map<int,int> vis;\n        vector<pair<int,int>> adj[n];\n        for(auto i:edges)\n        {\n            adj[i[0]].push_back({i[1],i[2]});\n            adj[i[1]].push_back({i[0],i[2]});\n        }\n        int maxi=-1;\n        int val=0;\n        dfs(0,adj,vis,mt,values,val,maxi);\n        return maxi;\n    }\n};\n```
['C++']