DFS || C++ || Easy To Understand
\nclass Solution {\n    vector<vector<pair<int,int>>> grp;\n    int ans;\n    void dfs(int u,int cost,int gain,vector<int>& values,vector<int> &vis){\n        i
```\nclass Solution {\n    vector<vector<pair<int,int>>> grp;\n    int ans;\n    void dfs(int u,int cost,int gain,vector<int>& values,vector<int> &vis){\n        if(!vis[u]) gain+=values[u];\n        if(u==0) ans=max(ans,gain);\n        vis[u]++;    \n        for(auto j:grp[u])\n            if(j.second<=cost) dfs(j.first,cost-j.second,gain,values,vis);\n        vis[u]--;\n    }\npublic:\n    int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxTime) {\n        int n=values.size();\n        grp.clear();\n        ans=0;\n        grp=vector<vector<pair<int,int>>> (n);\n        for(auto &i:edges){\n            grp[i[0]].push_back({i[1],i[2]});\n            grp[i[1]].push_back({i[0],i[2]});\n        }\n        vector<int> vis(n,0);\n        dfs(0,maxTime,0,values,vis);\n        return ans;\n    }\n};\n```\n\nPassed in 128 ms.
['Depth-First Search', 'C']