Created
August 24, 2019 02:59
-
-
Save c-yan/e0eb355e01b1c732c94820bd8d3d3026 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parent = [-1] * n | |
def find(parent, i): | |
if parent[i] < 0: | |
return i | |
parent[i] = find(parent, parent[i]) | |
return parent[i] | |
def unite(parent, i, j): | |
i = find(parent, i) | |
j = find(parent, j) | |
if i == j: | |
return | |
parent[j] += parent[i] | |
parent[i] = j | |
def size(parent, i): | |
return -parent[find(parent, i)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment