-
Notifications
You must be signed in to change notification settings - Fork 3
05 최단 경로 #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kimyeheun
wants to merge
9
commits into
main
Choose a base branch
from
05-kim
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dalsu0222
approved these changes
Mar 24, 2025
Node now = queue.poll(); | ||
if (path[now.node] != 0) continue; | ||
path[now.node] = now.route; | ||
for(Node n : routes.getOrDefault(now.node, new ArrayList<>())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
해시맵에 getOrDefault가 있는지 처음 알았네요!! 이 함수를 쓴 이유가 무엇인지 알 수 있을까욥
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
최단거리 문제 풀이 시 주의 사항
❗idea
💡코드 작성 전에
지름길
이번주 알고리즘 분류를 보고 무조건 다익스트라로 풀어야 겠다고 생각하고 문제를 접근한 것이 화근이었습니다.
처음에는 우선순위 큐에 <시작점, 끝점, 가중치>가 있는 노드를 넣고, 지름길로 얻을 수 있는 이득의 비율이 가장 큰 순서로 정렬하는 방식을 사용했습니다.
하지만, 이 문제는 단순히 가장 지름길을 먼저 선택한다고 해서 풀리는 문제가 아니라는 것을 깨달았습니다. (10%씩 줄어드는 지름길 두 개와 15% 줄어드는 지름길이 있다고 가정할 때, 10%씩 줄어드는 지름길 두 개를 선택하는 것이 훨씬 이득)
이후 알고리즘에 집중하지 않고 문제를 찬찬히 읽어보았습니다.
이와 같은 조건에서 dp로 풀 수 있겠다는 생각을 하게 되었고, 이대로 풀게 되었습니다.
숨바꼭질 3
서강그라운드
택배