Switch to DFS to solve constraint