C++ Solution
Code\ncpp []\nclass Solution {\nprivate:\n    int n,res, maxiTime;\npublic:\n    void dfs(vector<int>& values, vector<vector<pair<int,int>>>& graph,int node, in
# Code\n```cpp []\nclass Solution {\nprivate:\n    int n,res, maxiTime;\npublic:\n    void dfs(vector<int>& values, vector<vector<pair<int,int>>>& graph,int node, int time, int curr){\n        if(time > maxiTime){\n            return ;\n        }\n\n        int oldValue = values[node];\n        curr += oldValue;\n        values[node] = 0;\n        \n        if(node == 0){\n            res = max(res,curr);\n        }\n\n        for(int i = 0; i< graph[node].size(); i++){\n            dfs(values, graph, graph[node][i].first, time + graph[node][i].second, curr);\n        }\n\n        values[node] = oldValue;\n    }\n\n    int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxTime) {\n        n = values.size();\n        maxiTime = maxTime;\n        // creating graph.\n        vector<vector<pair<int,int>>> graph(n);\n        for(int i = 0; i < edges.size(); i++){\n            graph[edges[i][0]].push_back({edges[i][1],edges[i][2]});\n            graph[edges[i][1]].push_back({edges[i][0],edges[i][2]});\n        }\n\n        res = 0;\n        dfs(values, graph, 0, 0, 0);\n        return res;\n    }\n};\n```
['C++']