[20250806] BOJ / P3 / 사탕 배달 / 권혁준 #616
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/20295
🧭 풀이 시간
30분
👀 체감 난이도
✏️ 문제 설명
정점 N개인 트리의 각 점에 사탕의 종류 c[i]가 써있다. (1 <= c[i] <= 5)
친구 M명은 각각 점 p[i]에 살고 있으며, 종류가 k[i]인 사탕을 먹고 싶어 한다.
아무 곳에서나 시작해서, 각 친구를 순서대로 최단 경로를 따라 만나러 간다. i번 친구를 만나러 갈 때에는 i번 친구를 위한 사탕만을 살 수 있다.
각 친구들이 사탕을 받을 수 있는지 없는지 알아보자.
🔍 풀이 방법
아무 곳에서나 시작할 수 있으니까 일단 첫 번째 친구에 대해서는 그 친구가 원하는 사탕이 하나라도 존재한다면 가능하다.
이후부터는 이전에 있던 점과 현재 가야하는 점 사이의 경로에 해당하는 사탕의 비트마스크를 구해 원하는 사탕이 존재하는지 확인해줬다.
경로에 해당하는 비트마스크를 빠르게 구하기 위해 희소 배열을 사용했다.
⏳ 회고
배고파요