Implement finding connected components using DFS