@Override
	public void union(int p, int q)
	{
		int pRoot = find(p); // component of p
		int qRoot = find(q); // component of q

		// Do nothing if p and q belong to the same component
		if (pRoot == qRoot)
			return;

		// Take care to make smaller tree point to larger one thus keeping the
		// component-tree height relatively smaller
		if (height[pRoot] < height[qRoot])
		{
			// Label component-id of pRoot as qRoot, thus effectively making the
			// component-id of all vertices whose actual component-id was pRoot
			// (by the virtue of being led to pRoot through their
			// component-id's)
			// now as qRoot
			id[pRoot] = qRoot;

			height[qRoot] = height[pRoot] + 1;
			sz[qRoot] += sz[pRoot];
		}
		else
		{
			// vice-versa
			id[qRoot] = pRoot;
			height[pRoot] = height[qRoot] + 1;
			sz[pRoot] += sz[qRoot];
		}
		componentCount--;
	}