Working BFS.
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges,
                           int maxTime) {
        int n = values.size();
        vector<pair<int, int>> adj[n];

        for (int i = 0; i < edges.size(); i++) {
            int u = edges[i][0];
            int v = edges[i][1];
            int w = edges[i][2];
            adj[u].push_back({v, w});
            adj[v].push_back({u, w});
        }

        set<pair<int, pair<int, set<int>>>> q;
        q.insert({0, {0, {0}}});

        set<set<int>> anspth;

        while (!q.empty()) {
            auto it = *(q.begin()); 
            int curt = it.first;
            int node = it.second.first;
            set<int> curpath = it.second.second;
            q.erase(it);
            if (node == 0) {
                anspth.insert(curpath);
            }

            for (auto nbg : adj[node]) {
                int nbgnode = nbg.first;
                int delt = nbg.second;

                int newt = curt + delt;
                if (newt <= maxTime) {
                    bool ok = 0;
                    if (curpath.find(nbgnode) != curpath.end()) {
                        ok = 1;
                    }
                    curpath.insert(nbgnode);
                    q.insert({newt, {nbgnode, curpath}});
                    if (ok == 0) {
                        curpath.erase(nbgnode);
                    }
                }
            }
        }

        int ans = 0;

        for (auto it : anspth) {
            int temp = 0;
            for (auto it2 : it) {
                temp += values[it2];
            }
            ans = max(ans, temp);
        }

        return ans;
    }
};
```
['C++']