Skip to content

Instantly share code, notes, and snippets.

@rogerioagjr
Created May 18, 2015 18:50
Show Gist options
  • Save rogerioagjr/80368808de9d935c8576 to your computer and use it in GitHub Desktop.
Save rogerioagjr/80368808de9d935c8576 to your computer and use it in GitHub Desktop.
Find Otimizada
// 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