Find the number of connected components in undirected graph using Union Find
问题 I've been staring at this algorithm for a while but couldn't spot what I've missed. Logic: Init all isolated components union frm, to component in each edge and decrement # components if those components aren't already connected. Question: how come that I get this -48 when running this particular test case? def countComponents(self, n, edges): """ :type n: int :type edges: List[List[int]] :rtype: int """ roots = [i for i in range(n)] # track disconnected components # n isolated islands for u,