[C++] Super Short 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```\nclass Solution {\npublic:\n    int maximalPathQuality(vector<int>& v, vector<vector<int>>& e, int m) {\n        int res = 0, seen[1001]{};\n        vector<pair<int, int>> g[1001];\n        for(auto & i : e) {\n            g[i[0]].push_back({i[1], i[2]});\n            g[i[1]].push_back({i[0], i[2]});\n        }\n        auto dfs = [&](auto&& self, int n, int t, int cur) {\n            if(t < 0) return;\n            if(!seen[n]) cur += v[n];\n            if(n == 0) res = max(cur, res);\n            seen[n]++;\n            for(auto & c : g[n]) self(self, c.first, t-c.second, cur);\n            seen[n]--;\n        };\n        dfs(dfs, 0, m, 0);\n        return res;\n    }\n};\n```
['C++']