C++ backtracking
The key is to notice that the minimum time for an edge is 10, and the maximum time total is 100, which leads to a max amount of paths of 4 ^ 10\n\n\nclass Solut
The key is to notice that the minimum time for an edge is 10, and the maximum time total is 100, which leads to a max amount of paths of 4 ^ 10\n\n```\nclass Solution {\npublic:\n    vector<int> b, v;\n    vector<vector<pair<int,int>>> g;\n    int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxTime) {\n        b.resize(values.size());\n        g.resize(values.size());\n        v = values;\n        for (auto& e : edges)\n            g[e[0]].push_back({e[1], e[2]}),\n            g[e[1]].push_back({e[0], e[2]});\n        return dfs(0, maxTime);\n    }\n    \n    int dfs(int node, int t){\n        if (t < 0) return -1;\n        int ans = !node ? (!b[node] ? v[node] : 0) : -1;\n        ++b[node];\n        for (auto& [edgeNode, edgeCost] : g[node]){\n            int next = dfs(edgeNode, t - edgeCost);\n            if (next != -1)\n                ans = max(ans, (b[node] == 1) * v[node] + next);\n        }\n        --b[node];\n        return ans;\n    }\n};\n```
[]