dfs for finding cut point