DFS,Sort the array,AC