Easy explaination using DFS (Alternative of DSU)
Intuition\n Describe your first thoughts on how to solve this problem.  Separae graph into components and then find the bitwise AND of the weighted node in that
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. --> Separae graph into components and then find the bitwise AND of the weighted node in that component. If the nodes is same then answer is 0 and if the two nodes are not in same component then answer is -1.\n\n# Approach\n\n\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(V+E)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(V+E)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    void dfs(int i,vector<vector<pair<int,int>>> &adj,vector<int> &vis,int &mn,int cnt)\n    {\n        vis[i]=cnt;\n        for(auto x:adj[i])\n        {\n            if(vis[x.first]==-1)\n            {\n                // mn=mn & x.second;\n                dfs(x.first,adj,vis,mn,cnt);\n            }\n        }\n        \n    }\n    vector<int> minimumCost(int n, vector<vector<int>>& edges, vector<vector<int>>& query) {\n        vector<vector<pair<int,int>>> adj(n);\n        \n        for(auto e:edges)\n        {\n            adj[e[0]].push_back({e[1],e[2]});\n            adj[e[1]].push_back({e[0],e[2]});\n        }\n        \n        vector<int> vis(n,-1);\n        int cnt=-1;\n        // vector<int> min_weight;\n        for(int i=0;i<n;i++)\n        {\n            int mn=INT_MAX;\n            if(vis[i]==-1)\n            {\n                cnt++;\n                dfs(i,adj,vis,mn,cnt);\n                // min_weight.push_back(mn);\n            }\n        }\n\n        vector<int> min_weight(cnt+1,INT_MAX);\n        for(auto e:edges)\n        {\n            min_weight[vis[e[0]]]= min_weight[vis[e[0]]] & e[2]; \n        }\n        vector<int> ans;\n        for(auto q:query)\n        {\n            \n            if(vis[q[0]]!=vis[q[1]])\n                ans.push_back(-1);\n            else if(q[0]==q[1])\n                ans.push_back(0);\n            else ans.push_back(min_weight[vis[q[0]]]);\n        }\n        \n        return ans;\n    }\n};\n```
['Depth-First Search', 'C++']