[20250504] BOJ / G4 / 특정한 최단 경로 / 이강현 #323
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/1504
🧭 풀이 시간
60분
👀 체감 난이도
✏️ 문제 설명
종착지까지 특정한 경유지 두 곳을 꼭 거쳐서 가야하는 문제, 이때 방향성은 없음
🔍 풀이 방법
다익스트라
⏳ 회고
다익스트라의 최적화 과정을 깊게 이해하는게 중요했던 것 같다. 결론적으로는 1에서 N까지 가야하고 v1,v2를 꼭 지나야한다고 할때 1,v1,v2,N 과 1, v2,v1,N 둘 중 하나만 비교해서 최적을 결정할 수 있다는 건데, 사실 1에서 v1,v2 각각으로 가는 비용이 1이고 v1에서 v2 사이를 99, v1,v2에서 N까지를 1이라고 잡으면 1,v1,N,v2,N 이런식으로 가는게 가장 최적일 것임.

근데 다익스트라 알고리즘이 실행되면서 결국 최적 비용 배열은 인접경로 99가 아니라 v1->1->v2와 같은 경로로 최적화 되어 2가 될 것이므로 N을 먼저 가는 경우는 결국 v1,v2를 먼저 가는 방법에 이미 반영이 된다는 거였음.
이는 아래와 같은 삼각부등식 때문에 적용된다는 것을 배울 수 있었다.