c++ dfs
long long int max(long long int ans,long long int sum)\n{\n    return ans>=sum?ans:sum;\n}\nvoid fun(int a,vector>>& g,vector& values,int maxTime,long long int 
long long int max(long long int ans,long long int sum)\n{\n    return ans>=sum?ans:sum;\n}\nvoid fun(int a,vector<vector<pair<int,int>>>& g,vector<int>& values,int maxTime,long long int & sum,int & time,long long int & ans)\n{\n    if(a==0) {  ans=max(ans,sum);  }\n    for(auto x : g[a])\n    {\n        if((time+x.second)<=maxTime)\n        {\n            sum=sum+values[x.first];\n            int temp=values[x.first];\n            values[x.first]=0;\n            time=time+x.second;\n            fun(x.first,g,values,maxTime,sum,time,ans);\n            time=time-x.second;\n            sum=sum-temp;\n            values[x.first]=temp;\n        }\n    }\n}\nclass Solution {\npublic:\n    int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxTime) {       \n        long long int ans=INT_MIN;\n        int n=values.size();\n        vector<vector<pair<int,int>>> g(n);\n        for(auto x : edges)\n        {\n            g[x[0]].push_back(make_pair(x[1],x[2]));\n            g[x[1]].push_back(make_pair(x[0],x[2]));\n        }\n        ans=max(ans,values[0]);  long long int sum=values[0]; int time=0;  values[0]=0;\n        fun(0,g,values,maxTime,sum,time,ans);\n        return ans;\n    }\n};
[]