[20250906] BOJ / G2 / 멀지만 가까운 사이 / 권혁준 #829
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/34224
🧭 풀이 시간
25분
👀 체감 난이도
✏️ 문제 설명
트리에서 두 점 (u,v)의 경로를 따라 XOR한 값이 0이 되는 경우의 수를 구해보자.
🔍 풀이 방법
걍 아무거나 하나 루트로 잡고, 루트에서 어떤 점 v까지의 경로 xor을 dist[v]라고 하자.
(u,v)의 경로 xor이 0이라는 건 dist[u]와 dist[v]를 xor한 값이 0이라는 것과 동치임.
BFS로 dist배열을 채워줬고, dist값이 같은 점들의 개수를 이용해서 답을 구했다.
⏳ 회고
DFS 돌리니까 터지는데 BFS 돌리니까 맞음.
이건 억까 아닌가