[20250203] BOJ / 골드4 / 가장 먼 곳 / 권혁준 #3
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/22865
🧭 풀이 시간
20분
👀 체감 난이도
✏️ 문제 설명
정점이$N$ 개인 무방향 연결 그래프가 주어집니다.$1$ 부터 $N$ 까지 번호가 달려 있습니다.$A, B, C$ 가 주어지면, 이들로부터 가장 먼 곳을 구하는 문제입니다.
각 정점에는
정점의 번호 세 개
가장 먼 곳은 세 정점으로부터의 최단 거리 중 최솟값이 가장 먼 점을 말합니다.
🔍 풀이 방법
무방향(양방향) 그래프이기 때문에, 어떤 점$X$ 에서 $Y$ 로 가는 최단 경로와 $Y$ 에서 $X$ 로 가는 최단 경로는 동일합니다.
따라서 세 점을 시작점으로 두고 다익스트라 알고리즘을 수행하여 각각에 대한 최단 경로 배열을 얻어줍니다.
얻은 배열을 통해 가장 먼 곳을 구할 수 있습니다.
⏳ 회고
문제를 잘못 읽어서 답이 다르게 나왔었는데, 지문을 꼼꼼히 읽는 습관을 들여야겠다고 생각했습니다.