Easy DFS solution
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```cpp []\nclass Solution {\npublic:\n    int ans = -1;\n    void dfs(unordered_map<int,vector<pair<int,int>>> &adj,vector<int> &values,vector<int> &temp,int node,bool isFirst,int maxTime){\n        if(maxTime < 0){\n            return;\n        }\n        if(node == 0 && isFirst && maxTime >= 0){\n            int sum = 0;\n            vector<int> vis(values.size(),0);\n            for(auto val : temp){\n                if(!vis[val]){\n                    sum += values[val];\n                    vis[val] = 1;\n                }\n            }\n            ans = max(ans,sum);\n        }\n        isFirst = true;\n        for(auto val : adj[node]){\n            temp.push_back(node);\n            dfs(adj,values,temp,val.first,isFirst,maxTime-val.second);\n            temp.pop_back();\n        }\n    }\n    int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxTime) {\n        unordered_map<int,vector<pair<int,int>>> adj;\n        for(int i = 0;i<edges.size();i++){\n            adj[edges[i][0]].push_back({edges[i][1],edges[i][2]});\n            adj[edges[i][1]].push_back({edges[i][0],edges[i][2]});\n        }\n        vector<int> temp;\n        bool isFirst = false;\n        dfs(adj,values,temp,0,isFirst,maxTime);\n        if(ans == -1){\n            return values[0];\n        }\n        return ans;\n    }\n};\n```
['C++']