CPP || Disjoint Set Union || Graphs 
Intuitionits nothing but we just know that the and function is intersection of bits and the total &of all the weights can't be more than the smallest weighted e
# Intuition
its nothing but we just know that the and function is intersection of bits and the total &of all the weights can't be more than the smallest weighted edge in the component.
and the question mentioned u can visit nodes any number of times so we will visit all the nodes in the component to make the total and of all the component as minimum to be possible so that all the paths in the component will be the minimum & value of the component if two nodes are from different components no path exist.

# Approach
We can do this by DSU data struture and bu little modification we can get the required results u can see the code given below.

# Complexity
- Time complexity:
O((queries+edges)*(x))
x is inverse ackerman funtion which is nearly constant O(1) for the DSU operations

- Space complexity:
O(4*N+V+E)

# Code
```cpp []
class Solution {
public:
    vector<int> siz;
    vector<int> p;
    vector<int> val;
    void initialise(int n){
        siz.resize(n,1);
        val.resize(n,0);
        p.resize(n);
        for(int i=0;i<n;i++){
            p[i]=i;
        }
    }
    int findp(int a){
        if(p[a]==a) return p[a];
        return p[a]=findp(p[a]);
    }
    void uni(int a,int b){
        a=findp(a);
        b=findp(b);
        if(a!=b){
            if(siz[b]>siz[a]){
                swap(a,b);
            }
            val[a]&=val[b];
            p[b]=a;
            siz[a]+=siz[b];
        }
    }
    vector<int> minimumCost(int n, vector<vector<int>>& e, vector<vector<int>>& q) {
        initialise(n);
        for(int i=0;i<e.size();i++){
            if(findp(e[i][0])==findp(e[i][1])){
                val[findp(e[i][0])]&=e[i][2];
            }
            else{
                if(siz[findp(e[i][0])]==1){
                    val[findp(e[i][0])]=e[i][2];
                }
                else{
                     val[findp(e[i][0])]&=e[i][2];
                }
                if(siz[findp(e[i][1])]==1){
                    val[findp(e[i][1])]=e[i][2];
                }
                else{
                     val[findp(e[i][1])]&=e[i][2];
                }
                uni(e[i][0],e[i][1]);
            }
        }
        vector<int> ans(q.size());
        for(int i=0;i<q.size();i++){
            if(findp(q[i][0])!=findp(q[i][1])){
                ans[i]=-1;
            }
            else{
                ans[i]=val[findp(q[i][0])];
            }
        }
        return ans;
    }
};
```
['C++']