[Python] Simple double DSU O(E^2) solution
Not the fastest algorithm, but perhaps one of the easiest-to-code solutions during a contest. The code is plain and straight-forward:\npython\nclass DSU:\n    d
Not the fastest algorithm, but perhaps one of the easiest-to-code solutions during a contest. The code is plain and straight-forward:\n```python\nclass DSU:\n    def __init__(self, N: int):\n        # initially, every node forms a partition of size 1\n        self.par = list(range(N))   #             the partition to which every node belongs\n        self.sz = [1] * N           # the size of ...\n    \n    def find(self, x: int) -> int:\n        if self.par[x] != x:\n            self.par[x] = self.find(self.par[x])\n        return self.par[x]\n    \n    def union(self, x: int, y: int) -> bool:\n        xr, yr = self.find(x), self.find(y)\n        if xr == yr:\n            return False\n        if self.sz[xr] < self.sz[yr]:\n            xr, yr = yr, xr\n        self.par[yr] = xr\n        self.sz[xr] += self.sz[yr]\n        self.sz[yr] = self.sz[xr]\n        return True\n    \n    def size(self, x: int) -> int:\n        return self.sz[self.find(x)]\n\n\nclass Solution:\n    def findCriticalAndPseudoCriticalEdges(self, n: int, edges: List[List[int]]) -> List[List[int]]:\n        edges = sorted((w, u, v, i) for i, (u, v, w) in enumerate(edges))\n        critical, pseudo = [], []\n        for _w, _u, _v, i in edges:\n            dsu1, dsu2 = DSU(n), DSU(n)\n            dsu1.union(_u, _v)\n            s1, s2 = _w, 0\n            for w, u, v, j in edges:\n                if i == j:\n                    continue\n                if dsu1.union(u, v):\n                    s1 += w\n                if dsu2.union(u, v):\n                    s2 += w\n            if s1 == s2:\n                pseudo.append(i)\n            elif s1 < s2 or dsu2.union(_u, _v):\n                critical.append(i)\n        return critical, pseudo\n```\nVote up if you find this helpful, thanks!
['Python']