DFS with different comparison