Merged
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
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.
🧷 문제 링크
https://www.acmicpc.net/problem/1219
🧭 풀이 시간
35분
👀 체감 난이도
✏️ 문제 설명
N개의 도시와 M개의 일방통행 도로로 이루어진 그래프가 있다.
i번째 도로를 이용하려면 c[i]만큼의 돈을 내야 하고, j번째 도시에 도착하면 d[j]만큼의 돈을 얻는다.
같은 도로를 여러 번 이용할 수 있고, 같은 도시에 여러 번 도착하면 매번 돈을 얻는다.
도시 A에서 출발해서 도시 B에 도착할 때, 가지게 되는 돈의 최댓값을 구해보자.
도착이 불가능하면
gg, 돈의 최댓값이 무한하다면Gee를 대신 출력🔍 풀이 방법
돈을 cost와 반대되는 개념으로 본다면, 그래프에서 최단 경로를 찾는 문제가 된다.
문제는, 간선의 가중치가 음수일 수 있다는 점이다.
음의 사이클을 탐지할 수 있어야 하니까 벨만-포드를 써야 한다.
도시 A로부터 이 음의 사이클로 도달 가능해야 하고, 이 음의 사이클에서 도착 도시 B로 도달이 가능해야 한다. -> 그래프 탐색으로 전처리가 가능
⏳ 회고
음의 사이클과의 도달 가능성 여부를 체크하지 않아서 재미없어질뻔함