solved using simple dfs, no DSU used
Intuition\n Describe your first thoughts on how to solve this problem. \nrun dfs and make the intial source vertex as parent of all it connected component.\n\ns
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nrun dfs and make the intial source vertex as parent of all it connected component.\n\nsince in question it is given that that we can visit same path any number of time, hence for any two vertex which is connected directly or indirectly will have cost=(AND of all edge in that connected component)\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\nAND property=>a&a=a, a&b&b&a&c&d&d=a&b&c&d.\nmeans no matter how many time we do AND operation answer will not change.\n\nIn the end for each query I have checked\n1=> if (parent of vertex1 and parent of vertex2 is not same)\n     means they are not in same connected component so ans=-1;\n2=> else if (both vertex are same )then answer will be 0 \n\n3=> else ans will (AND of all edge weights in that connected component)\n\n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO((v+e)logv)\n\n- Space complexity:\n- O(v+e)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    void dfs(vector<int>&p,int srcc,int src,vector<int>&vis,vector<pair<int,int>>adj[]){\n        vis[src]=1;\n        p[src]=srcc;\n        \n        for(auto it:adj[src]){\n            if(!vis[it.first]){\n               \n                p[it.first]=srcc;\n            dfs(p,srcc,it.first,vis,adj);\n            }\n        }\n    }\n    vector<int> minimumCost(int n, vector<vector<int>>& edges, vector<vector<int>>& query) {\n        vector<pair<int,int>>adj[n+1];\n        for(auto it:edges){\n            adj[it[0]].push_back({it[1],it[2]});\n            adj[it[1]].push_back({it[0],it[2]});\n        }\n        vector<int>vis(n+1);\n        vector<int>p(n+1);\n        map<int,int>mp;\n        for(int i=0;i<n;i++){\n            if(!vis[i]){\n               \n                dfs(p,i,i,vis,adj);\n               \n                \n            }\n        }\n        for(int i=0;i<n;i++){\n             int mn=1<<20;\n                mn--;\n            mp[p[i]]=mn;\n        }\n         for(auto it:edges){\n            // adj[it[0]].push_back({it[1],it[2]});\n            // adj[it[1]].push_back({it[0],it[2]});\n             \n             mp[p[it[0]]]&=it[2];\n             mp[p[it[1]]]&=it[2];\n             \n        }\n        \n        \n        vector<int>ans;\n        for(auto it:query){\n            if(p[it[0]]!=p[it[1]])ans.push_back(-1);\n            else if(it[0]==it[1]){\n                ans.push_back(0);\n            }\n            else  ans.push_back(mp[p[it[0]]]);\n        }\n        return ans;\n        \n    }\n};\n```\n\n\nplease upvote if it is helpful
['Bit Manipulation', 'Depth-First Search', 'Union Find', 'C++']