𝐟 𝐨 𝐫 𝑖 = 1 t o 𝑁 𝑒 𝐝 𝐨
Read the 𝑖 th edge: ( 𝑝 1 , 𝑝 2 )
𝑆 1 = F I N D ( 𝑝 1 )
𝑆 2 = F I N D ( 𝑝 2 )
𝐢 𝐟 𝑃 ( 𝑆 1 , 𝑆 2 ) = T r u e 𝐭 𝐡 𝐞 𝐧
U N I O N ( 𝑆 1 , 𝑆 2 )
𝐞 𝐧 𝐝 𝐢 𝐟
𝐞 𝐧 𝐝 𝐟 𝐨 𝐫
Algorithm 1: Merging regions algorithm.