[20251002] PGM / Lv2 / 도넛과 막대 그래프 / 이강현 #1025
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🧷 문제 링크
https://school.programmers.co.kr/learn/courses/30/lessons/258711
🧭 풀이 시간
120분
👀 체감 난이도
✏️ 문제 설명
<도넛 모양>



<막대 모양>
<8자 모양>
세 가지 모양의 그래프들이 있음. 임의의 하나의 정점을 추가해서 이들과 연결했음.
이때, 추가한 정점과 위 세가지 모양의 그래프들이 몇 개 존재하는지 출력하셈.
[추가한 정점, 도넛 모양 그래프 개수, 막대 모양 그래프 개수, 8자 모양 그래프 개수] 형태로 출력.
🔍 풀이 방법
BFS
일단 2개 이상의 인접 노드를 가진 애들을 걸러내고 이중에 유일하게 자신을 가리키지 않는 정점이 추가한 노드임.
그리고 추가한 노드에서 BFS를 각각 실행함.(DFS도 될거임)
인접한 노드가 없는 노드에 도달하면 막대그래프
인접한 노드가 2개 이상인 노드에 도달하면 8자 그래프
이미 왔던 노드라면 도넛 그래프
⏳ 회고
그리 어렵진 않은 문제인데, 흔히 푸는 모습의 BFS가 아니어서 그런가 자꾸 헷갈렸다.