Plain DFS
Perhaps this problem would be more interesting if we have more nodes, or max time is not limited to 100.\n\nHere, we first build an adjacency list, and then run
Perhaps this problem would be more interesting if we have more nodes, or max time is not limited to `100`.\n\nHere, we first build an adjacency list, and then run DFS, subtracting time and tracking the current value.\n\nThe visited array helps us determine when a node is visited for the first time. We add the node value when we visit the node for the first time.\n\n**C++**\n```cpp\nint max_val = 0;\nint dfs(vector<vector<pair<int, int>>> &al, vector<int> &vis, vector<int>& vals, int i, int time, int val) {\n    val += (++vis[i] == 1) ? vals[i] : 0;\n    if (i == 0)\n        max_val = max(max_val, val);\n    for (auto [j, t] : al[i])\n        if (time - t >= 0)\n            dfs(al, vis, vals, j, time - t, val);\n    --vis[i];\n    return max_val;\n}\nint maximalPathQuality(vector<int>& vals, vector<vector<int>>& edges, int maxTime) {\n    vector<vector<pair<int, int>>> al(vals.size());\n    vector<int> vis(vals.size());\n    for (auto &e : edges) {\n        al[e[0]].push_back({e[1], e[2]});\n        al[e[1]].push_back({e[0], e[2]});\n    }\n    return dfs(al, vis, vals, 0, maxTime, 0);\n}\n```
[]