[20251209] BOJ / G4 / 자벌레 세기 / 권혁준 #1626
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://www.acmicpc.net/problem/34875
🧭 풀이 시간
5분
👀 체감 난이도
✏️ 문제 설명
N개의 정점으로 구성된 트리가 있다.
어떤 6개의 서로 다른 정점 (u,v,w,x,y,z)가 다음 조건을 만족하는 경우를 자벌레라고 한다.
🔍 풀이 방법
간선 u-v를 고정시키면, w, x, y, z를 고르는 경우는 (u와 연결된 점의 개수 - 1)에서 두 개, (v와 연결된 점의 개수 - 1)에서 두 개를 고르는 것과 같다.
정점 n의 차수를 deg[n]이라고 정의하면, 위 값은 ((deg[u]-1)(deg[u]-2)/2) * ((deg[v]-1)(deg[v]-2)/2)가 된다.
모든 간선에 대해 계산한 값을 합쳐줬다.
⏳ 회고
문제에서 예시 그림을 줘서 더 빨리 풀이를 찾을 수 있었다. 앞으로 이런 문제가 나오면 일단 그려보자.