[20250407] BOJ / P4 / 산책 (large) / 권혁준 #300
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/22870
🧭 풀이 시간
40분
👀 체감 난이도
✏️ 문제 설명
정점 N개 간선 M개인 양방향 그래프와 S, E가 주어진다.
산책은 S에서 E로 갔다가 다시 S로 되돌아오는 것을 의미한다.
S에서 E로 갈 때는 최단 거리이면서 동시에 사전 순으로 가장 앞서는 경로를 선택한다.
E에서 다시 S로 돌아올 때는 이전에 지나왔던 정점을 지나지 않으면서 최단 거리로 이동한다.
산책의 경로 길이를 구해보자.
🔍 풀이 방법
[사용한 알고리즘]
S에서 E로 가는 사전 순으로 가장 빠른 경로를 찾기 위해, E를 시작점으로 두고 다익스트라를 수행한다.
그 다음, S에서부터 간선을 하나씩 탐색하며 E로 가는 경로를 구해 방문 처리를 해놓는다.
다시 E에서 시작하는 다익스트라를 돌려 되돌아가는 경로를 구해준다.
⏳ 회고
어렵다