Created
September 16, 2019 15:17
-
-
Save lawrencechen0921/c767c59b8b46ecf0d6631418edaef7f0 to your computer and use it in GitHub Desktop.
Union Find
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 static void main(String[ ] args) | |
{ | |
int N = StdIn. readInt( ); | |
UF uf = new UF(N) ; | |
while (! StdIn . isEmpty( ) ) | |
{ | |
int p = StdIn . readInt( ); | |
int q = StdIn . readInt( ); | |
if (! uf . connected(p, q) ) | |
{ | |
uf . union (p , q); | |
StdOut. printIn( p + " " + q); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment