(C++) 2065. Maximum Path Quality of a Graph
Based on @votrubac\'s solution\n\nclass Solution {\npublic:\n    int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxTime) {\n       
Based on @votrubac\'s solution\n```\nclass Solution {\npublic:\n    int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxTime) {\n        int n = values.size(); \n        vector<vector<pair<int, int>>> graph(n); \n        for (auto& x : edges) {\n            graph[x[0]].emplace_back(x[1], x[2]); \n            graph[x[1]].emplace_back(x[0], x[2]); \n        }\n        \n        int ans = 0; \n        vector<int> freq(n); freq[0] = 1; \n        \n        function<void(int, int, int)> fn = [&](int u, int time, int val) {\n            if (u == 0) ans = max(ans, val); \n            for (auto& [v, t] : graph[u]) \n                if (time + t <= maxTime) {\n                    if (++freq[v] == 1) fn(v, time+t, val + values[v]); \n                    else fn(v, time+t, val); \n                    --freq[v]; \n                }\n        }; \n        \n        fn(0, 0, values[0]); \n        return ans; \n    }\n};\n```
['C']