You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
개선된 다익스트라 자바 코드에서 cost 부분이 dist 가 아닌 d[now] 가 오는게 잘 이해가 안됩니다.
아래 내용의 설명을 봤을때 dist가 d[now] 보다 작거나 같은 경우 이후 for문을 돌릴 수 있는 것 같은데
굳이 dist보다 크거나 같은 d[now]로 cost를 계산하는 이유가 있나요? 단순히 생각했을때 더 작거나 같은 dist로 cost를 계산하는게
맞는거 같은데 해당 부분이 잘 이해가 안됩니다. 실제로 c++, 파이썬에서는 dist로 계산하셨는데 자바만 다르더라구요 이유가 있을까요?
// 현재 노드가 이미 처리된 적이 있는 노드라면 무시if (d[now] < dist) continue;
// 현재 노드와 연결된 다른 인접한 노드들을 확인for (inti = 0; i < graph.get(now).size(); i++) {
intcost = d[now] + graph.get(now).get(i).getDistance();
// 현재 노드를 거쳐서, 다른 노드로 이동하는 거리가 더 짧은 경우if (cost < d[graph.get(now).get(i).getIndex()]) {
d[graph.get(now).get(i).getIndex()] = cost;
pq.offer(newNode(graph.get(now).get(i).getIndex(), cost));
}
}
The text was updated successfully, but these errors were encountered:
python-for-coding-test/9/2.java
Line 56 in 7c35923
개선된 다익스트라 자바 코드에서 cost 부분이 dist 가 아닌 d[now] 가 오는게 잘 이해가 안됩니다.
아래 내용의 설명을 봤을때 dist가 d[now] 보다 작거나 같은 경우 이후 for문을 돌릴 수 있는 것 같은데
굳이 dist보다 크거나 같은 d[now]로 cost를 계산하는 이유가 있나요? 단순히 생각했을때 더 작거나 같은 dist로 cost를 계산하는게
맞는거 같은데 해당 부분이 잘 이해가 안됩니다. 실제로 c++, 파이썬에서는 dist로 계산하셨는데 자바만 다르더라구요 이유가 있을까요?
The text was updated successfully, but these errors were encountered: