-
-
Save karmiclychee/4ff52ec0c8226769d960 to your computer and use it in GitHub Desktop.
This file contains 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
public int find(int p) { | |
if (p < 0 || p >= id.length) throw new IndexOutOfBoundsException(); | |
while (p != id[p]) { | |
id[p] = id[id[p]]; // path compression by halving | |
p = id[p]; | |
} | |
return p; | |
} |
Author
karmiclychee
commented
Jun 26, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment