C++ || DSU || Easy approach
Here is my c++ code for this problem.\n\n# Complexity\n- Time complexity:O(E*E)\n\n- Space complexity:O(E)\n\n# Code\n\nclass disjointset{\n    public:\n    vec
Here is my c++ code for this problem.\n\n# Complexity\n- Time complexity:O(E*E)\n\n- Space complexity:O(E)\n\n# Code\n```\nclass disjointset{\n    public:\n    vector<int>par, rank;\n    disjointset(int n){\n        par.resize(n+1);\n        rank.resize(n+1, 0);\n        for(int i=0; i<=n; i++){\n            par[i]=i;\n        }\n    }\n    int findp(int u){\n        if(u==par[u]){return u;}\n        return par[u]=findp(par[u]);\n    }\n    void un(int u, int v){\n        int pu=findp(u), pv=findp(v);\n        if(pu==pv){return;}\n        if(rank[pu]<rank[pv]){\n            par[pu]=pv;\n        }\n        else{\n            par[pv]=pu;\n            rank[pu]++;\n        }\n    }\n};\nclass Solution {\npublic:\n    int mst(int n, vector<pair<int, pair<int, int>>>& v, pair<int, pair<int, int>>a, pair<int, pair<int, int>>b){\n        disjointset d(n);\n        int ans=0;\n        if(a.second.first!=-1 && a.second.second!=-1){d.un(a.second.first, a.second.second); ans+=a.first;}\n        //if(b.second.first!=-1 && b.second.second!=-1){d.un(b.second.first, b.second.second);}\n        for(auto it: v){\n            if(b!=it && (d.findp(it.second.first)!=d.findp(it.second.second))){\n                ans+=it.first;\n                d.un(it.second.first, it.second.second);\n            }\n        }\n        set<int>s;\n        for(int i=0; i<n; i++){s.insert(d.findp(i));}\n        if(s.size()==1){return ans;}\n        return INT_MAX;\n    }\n    vector<vector<int>> findCriticalAndPseudoCriticalEdges(int n, vector<vector<int>>& edges) {\n        vector<pair<int, pair<int, int>>>v;\n        vector<vector<int>>ans;\n        vector<int>c, p;\n        int i=0;\n        map<pair<int, int>, int>m;\n        for(auto it: edges){\n            v.push_back({it[2], {it[0], it[1]}});\n            m[{it[0], it[1]}]=i;\n            i++;\n        }\n        sort(v.begin(), v.end());\n        int sum=mst(n, v, {-1, {-1, -1}}, {-1, {-1, -1}});\n        //cout<<sum<<endl;\n        for(auto it: v){\n            int s1=mst(n, v, {-1, {-1, -1}}, it), s2=mst(n, v, it, {-1, {-1, -1}});\n            cout<<sum<<" "<<s1<<" "<<s2<<endl;\n            if(s1>sum){c.push_back(m[{it.second.first, it.second.second}]);}\n            else{\n                if(s2==sum){p.push_back(m[{it.second.first, it.second.second}]);}\n            }\n        }\n        ans.push_back(c);\n        ans.push_back(p);\n        return ans;\n    }\n};\n```
['Union Find', 'Graph', 'Sorting', 'Heap (Priority Queue)', 'C++']