Java, Example of Union-Find Application