C++ || simple and easy DFS solution || 🚀🚀beats 80% 🚀🚀
\n# Code\n\nclass Solution {\npublic:\n    void dfs(int node, vector<int>& values, vector<vector<pair<int,int>>>& edges, int& ans, int maxTime, int time, int co
\n# Code\n```\nclass Solution {\npublic:\n    void dfs(int node, vector<int>& values, vector<vector<pair<int,int>>>& edges, int& ans, int maxTime, int time, int cost) {\n        if (time > maxTime) return;\n\n        cost += values[node];\n        if (node == 0) ans = max(ans, cost);\n        \n        //use the value of the node once\n        int tmp = 0;\n        swap(values[node], tmp);\n\n        //go to the adjacent nodes\n        for (auto edge : edges[node]) \n            dfs(edge.first, values, edges, ans, maxTime, time+edge.second, cost);\n        //we can use the values of nodes again\n        swap(values[node], tmp);\n    }\n    int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxTime) {\n        ios_base::sync_with_stdio(false);\n\t\tcin.tie(NULL);\n\t\tcout.tie(NULL);\n\n        int n = values.size();\n        vector<vector<pair<int, int>>> e(n);\n        int ans = 0;\n\n        for (auto edge : edges) {\n            e[edge[0]].push_back({edge[1], edge[2]});\n            e[edge[1]].push_back({edge[0], edge[2]});\n        }\n\n        dfs(0, values, e, ans, maxTime, 0, 0);\n        return ans;\n    }\n};\n```
['Backtracking', 'Depth-First Search', 'C++']