Created
May 18, 2015 18:50
-
-
Save rogerioagjr/80368808de9d935c8576 to your computer and use it in GitHub Desktop.
Find Otimizada
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
// função find otimizada | |
int find(int x){ | |
// se x for o patriarca, retorne x | |
if(pai[x]==x) return x; | |
// se não, retorne o valor do patriarca de seu pai | |
return pai[x]=find(pai[x]); // mas lembre-se de salvá-lo em pai[x] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment