depth-first search was implemented