Division into groups
IntuitionApproachHash map and division into groups division into groups of unrelated graphs.Complexity
Time complexity:

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

# Approach
Hash map and division into groups division into groups of unrelated graphs.

# 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:
    vector<int> minimumCost(int n, vector<vector<int>>& edges, vector<vector<int>>& query) {
        int size_edges = edges.size();
        int size_query = query.size();
        if (size_edges == 0) 
        {
            return {-1};
        }
        std::unordered_map<int, int> mp1;
        std::unordered_map<int, int> mp2;
        int group {1};
        for (int i{}; i < size_edges; ++i)
        {
            int sum = edges[i][2];
            if (!mp1.contains(edges[i][0]) && !mp1.contains(edges[i][1]))
            {
                mp2[group] = sum;
                mp1[edges[i][0]] = group;
                mp1[edges[i][1]] = group;
                ++group;
            }
            else
            {
                int g{};
                if (mp1.contains(edges[i][0]))
                {
                    sum &= mp2[mp1[edges[i][0]]];
                    g = mp1[edges[i][0]];
                    if (mp1.contains(edges[i][1]) && g != mp1[edges[i][1]])
                    {
                        int gr = mp1[edges[i][1]];
                        sum &= mp2[mp1[edges[i][1]]];
                        for (auto &pair : mp1)
                        {
                            if (pair.second == gr)
                            {
                                pair.second = g;
                            }
                        }
                    }
                    mp1[edges[i][1]] = g;
                    mp2[g] = sum;
                }
                else
                {
                    sum &= mp2[mp1[edges[i][1]]];
                    g = mp1[edges[i][1]];
                    mp2[g] = sum;
                    mp1[edges[i][0]] = g;

                }
            }
        }
        std::vector<int> answer(size_query, -1);
        for (int i{}; i < size_query; ++i)
        {
            if (mp1[query[i][0]] != 0 && mp1[query[i][0]] == mp1[query[i][1]])
            {
                answer[i] = mp2[mp1[query[i][0]]];
            }
        }
        return answer;
        
    }
};
```
['Ordered Map', 'C++']