vertices connected function