connected components and mnemonics algo