Dfs Algorithm In Python Using A Global Variable