C++ || DSU (good use of concepts) || Day 19
Code\n\nclass Solution {\npublic:\n    vector<int>parent;\n    void disjoint(int size){\n        parent.resize(size+1);\n        for(int i=0;i<=size;i++)\n     
# Code\n```\nclass Solution {\npublic:\n    vector<int>parent;\n    void disjoint(int size){\n        parent.resize(size+1);\n        for(int i=0;i<=size;i++)\n        parent[i]=(i);\n    }\n    int find(int u){\n        if(parent[u]==u)return u;\n        return parent[u] = find(parent[u]);\n    }\n    void merge(int u,int v){\n        int ua = find(u);\n        int ub = find(v);\n        parent[ua] = ub;\n    }\n    int help1(vector<vector<int>>& e,int j,int n){\n        disjoint(n+1);\n        vector<pair<int,pair<int,int>>>v;\n        for(int i=0;i<e.size();i++){\n            if(i==j)continue;\n            v.push_back({e[i][2],{e[i][0],e[i][1]}});\n        }\n        sort(v.begin(),v.end());\n        int mst_weight = 0;\n        int edges = 0;\n        for(int i=0;i<v.size();i++){\n            auto x = v[i];\n            int u = find(x.second.first);\n            int v = find(x.second.second);\n            if(u!=v){\n                edges++;\n                mst_weight += x.first;\n                merge(u,v);\n            } \n        }\n        if(edges!=n-1)return INT_MAX;\n        return mst_weight;\n    }\n    int help2(vector<vector<int>>& e,int j,int n){\n        disjoint(n+1);\n        int mst_weight = e[j][2];\n        merge(e[j][1],e[j][0]);\n        vector<pair<int,pair<int,int>>>v;\n        for(int i=0;i<e.size();i++){\n            if(i==j)continue;\n            v.push_back({e[i][2],{e[i][0],e[i][1]}});\n        }\n        sort(v.begin(),v.end());\n        for(int i=0;i<v.size();i++){\n            auto x = v[i];\n            int u = find(x.second.first);\n            int v = find(x.second.second);\n            if(u!=v){\n                mst_weight += x.first;\n                merge(u,v);\n            } \n        }\n        return mst_weight;\n    }\n    vector<vector<int>> findCriticalAndPseudoCriticalEdges(int n, vector<vector<int>>& e) {\n        disjoint(n+1);\n        int mst_weight = help1(e,-1,n);\n        vector<vector<int>>ans;\n        vector<int>v1,v2;\n        for(int i=0;i<e.size();i++){\n            int new_weight1 = help1(e,i,n);\n            int new_weight2 = help2(e,i,n);\n            if(new_weight1 > mst_weight){\n                v1.push_back(i);\n            }\n           else if(new_weight2 == mst_weight){\n                v2.push_back(i);\n            }\n        }\n        ans.push_back(v1);\n        ans.push_back(v2);\n        return ans;\n    }\n};\n```\n![upvote (2).jpg](https://assets.leetcode.com/users/images/45352c8f-4604-4f6e-bda0-eb904980ea7a_1692444615.6198385.jpeg)\n
['Union Find', 'Sorting', 'Minimum Spanning Tree', 'Strongly Connected Component', 'C++']