Simple easy to understand
Code\n\nclass Solution {\npublic:\n    int ans=0;\n    void dfs(int node,int maxTime,vector<int> &vis,vector<vector<pair<int,int>>> &adj,int &sum,vector<int> &v
# Code\n```\nclass Solution {\npublic:\n    int ans=0;\n    void dfs(int node,int maxTime,vector<int> &vis,vector<vector<pair<int,int>>> &adj,int &sum,vector<int> &values){\n        vis[node]++;\n        if(vis[node]==1) sum+=values[node];\n        if(node==0) ans=max(ans,sum);\n        for(auto it:adj[node]){\n            if(it.second<=maxTime){\n                dfs(it.first,maxTime-it.second,vis,adj,sum,values);\n            }\n        }\n        vis[node]--;\n        if(vis[node]==0) sum-=values[node];\n    }\n    int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxTime) {\n        int n=values.size();\n        vector<vector<pair<int,int>>> adj(n);\n        for(int i=0;i<edges.size();i++){\n            int u=edges[i][0],v=edges[i][1],wt=edges[i][2];\n            adj[u].push_back({v,wt});\n            adj[v].push_back({u,wt});\n        }\n        vector<int> vis(n,0);\n        int sum=0;\n        dfs(0,maxTime,vis,adj,sum,values);\n        return ans;\n    }\n};\n```
['C++']