Here is the implementation:
function unite(i, j):
rootA = find(i)
rootB = find(j)
if rootA != rootB:
if size[rootA] < size[rootB]:
swap(rootA, rootB)
parent[rootB] = rootA
size[rootA] = size[rootA] + size[rootB]
This runs in amortized time and uses space.