union-find algorithm, still case 4 not pased
dfs algorithm, AC