A More Intuitive dfs implementation using returned value instead of pararmeter.
Intuition\n Describe your first thoughts on how to solve this problem. \nYou can read the other\'s intuition as it is pretty straightforward.\n\n# Approach\n De
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nYou can read the other\'s intuition as it is pretty straightforward.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nAll the solutions I saw were actually storing the answer as some parameter and if was zero we will store the max answer.\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> vis;\n    int res;\n\n    int dfs(int i, vector<vector<pair<int,int>>> &graph, int maxi, vector<int> &values, int cost) {\n        int ans = INT_MIN;// if we can\'t go anywhere from this node as ends here but it\n        // cost is higher than allowed means the path  can only end on zero so we return -inf. if it does return 0;\n\n        if (i == 0) ans = 0;\n        int val = vis[i] == 0 ? values[i] : 0;\n        vis[i]++;\n        \n        for (auto &it : graph[i]) {\n            if (cost + it.second <= maxi) {\n                int temp = dfs(it.first, graph, maxi, values, cost + it.second);// if from this node we can form a valid path it will return some value not infity\n                ans = max(ans, val + temp); //this represent the answer at 0 all the paths will be computed and the maximum out of them will be returned\n            }\n        }\n        \n        vis[i]--;\n        return ans;\n    }\n\n    int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxi) {\n        int n = values.size();\n        res = values[0];\n        vis.resize(n, 0);\n        vector<vector<pair<int, int>>> graph(n);\n        \n        for (auto &edge : edges) {\n            graph[edge[0]].emplace_back(edge[1], edge[2]);\n            graph[edge[1]].emplace_back(edge[0], edge[2]);\n        }\n        \n        vis[0] = 1;\n        int result = dfs(0, graph, maxi, values, 0);\n        vis[0] = 0;\n        return result+values[0];\n    }\n};\n\n```
['C++']