c++ | easy | short
\n# Code\n\nclass Solution {\npublic:\n  class DSU\n{\n    public:\n    int findParent(int node,vector<int>& par)\n    {\n        if(par[node]==node)return node
\n# Code\n```\nclass Solution {\npublic:\n  class DSU\n{\n    public:\n    int findParent(int node,vector<int>& par)\n    {\n        if(par[node]==node)return node;\n        return par[node]=findParent(par[node],par);\n    }\n    void Union(int u,int v,vector<int> &size,vector<int> &par)\n    {\n        int pu=findParent(u,par);\n        int pv=findParent(v,par);\n        if(pu==pv)return;\n        if(size[pu]<=size[pv])\n        {\n            par[pu]=pv;\n            size[pv]++;\n        }\n        else\n        {\n            par[pv]=pu;\n            size[pu]++;\n        }\n    }\n};\n    \n    static bool comp(vector<int> &v1,vector<int> &v2)\n    {\n        return v1[2]<v2[2];        \n    }\n    vector<vector<int>> findCriticalAndPseudoCriticalEdges(int n, vector<vector<int>>& edges) \n    {\n        int len=edges.size();\n        for(int i=0;i<len;i++)\n            edges[i].push_back(i);\n  \n        sort(edges.begin(),edges.end(),comp);\n \n        DSU dsu;\n        int cost=0;\n        vector<int> par(n);\n        vector<int> size(n,1);\n        for(int i=0;i<n;i++)par[i]=i;\n        vector<bool> isPart(len,0);\n        int c=0;\n        for(int i=0;i<len;i++)\n        {   \n            if(c==n-1)break;\n            if(dsu.findParent(edges[i][0],par)!=dsu.findParent(edges[i][1],par))\n            {   \n                dsu.Union(edges[i][0],edges[i][1],size,par);\n                isPart[edges[i][3]]=1;\n                cost+=edges[i][2];\n                ++c;\n            }\n        }\n        vector<int> critical,pseudocritical;\n        for(int i=0;i<len;i++)\n        {\n            DSU tempDSU;\n            vector<int> tempPar(n,0);\n            for(int j=0;j<n;j++)tempPar[j]=j;\n            \n            vector<int> tempSize(n,1);\n            int tempCost=0;\n            vector<bool> temp(len,0);\n            int c=0;\n            for(int j=0;j<len;j++)\n            {   \n                if(c==n-1)break;\n                if(j==i)continue;               \n                if(tempDSU.findParent(edges[j][0],tempPar)!=tempDSU.findParent(edges[j][1],tempPar))\n                {\n                    tempDSU.Union(edges[j][0],edges[j][1],tempSize,tempPar);\n                    temp[edges[j][3]]=1;\n                    tempCost+=edges[j][2];\n                    c++;\n                }\n            }\n            if(tempCost==cost)\n            {\n                for(int k=0;k<len;k++)\n                {\n                    if(temp[k])isPart[k]=1;\n                }    \n            }\n            else\n                critical.push_back(edges[i][3]);\n        }\n        \n        for(int i=0;i<len;i++)\n        {\n            if(isPart[edges[i][3]])continue;\n            DSU tempDSU;\n            vector<int> tempPar(n,0);\n            for(int j=0;j<n;j++)tempPar[j]=j;\n            vector<int> tempSize(n,1);\n            int tempCost=0;\n            tempDSU.Union(edges[i][0],edges[i][1],tempSize,tempPar);\n            tempCost+=edges[i][2];\n            int c=0;\n            for(int j=0;j<len;j++)\n            {  \n                if(c==n-1)break;\n                if(j==i)continue;               \n                if(tempDSU.findParent(edges[j][0],tempPar)!=tempDSU.findParent(edges[j][1],tempPar))\n                {\n                    tempDSU.Union(edges[j][0],edges[j][1],tempSize,tempPar);\n                    tempCost+=edges[j][2];\n                    ++c;\n                }\n            }\n            if(tempCost==cost)\n                pseudocritical.push_back(edges[i][3]);\n        }\n        for(auto &it : critical)\n            isPart[it]=0;\n        for(int i=0;i<len;i++)\n        {\n            if(isPart[i])\n                pseudocritical.push_back(i);\n        }\n        return {critical,pseudocritical};\n    }\n};\n```
['C++']