Skip to content

단절점의 판단에 대한 질문 #11

Answered by wjdgns7712
yukyeongmin asked this question in Q&A
Discussion options

You must be logged in to vote
static int dfs(int id, boolean isRoot, int parent){
        order[id] = cnt++;
        int ret = order[id];
        int child = 0;
        for (int now : tree[id]) {
            if (now == parent) continue;
            
            if (order[now]==0){ // 아직 방문한 적이 없다면 child를 추가!
                child++;
                int low = dfs(now, false, id);
                if (!isRoot && low >= order[id])
                    answer.add(id);
                ret = Math.min(ret, low);
            } else
                ret = Math.min(ret, order[now]);
        }
        if (isRoot && child>=2) // 시작점이고 자식의 수가 2 이상이라면 단절점.
            answer.add(id);
        return ret;
    }

다른건 볼거없을거같고 주석부분만 보시면 될거같아요.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@yukyeongmin
Comment options

yukyeongmin Aug 13, 2021
Maintainer Author

@wjdgns7712
Comment options

Answer selected by wjdgns7712
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants