[20260225] BOJ / P4 / 도시 왕복하기 1 / 이강현#1966
Merged
ShinHeeEul merged 1 commit intomainfrom Feb 25, 2026
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/17412
🧭 풀이 시간
120분
👀 체감 난이도
✏️ 문제 설명
1부터 2까지 가는 경로의 최대 개수를 구한다.
특정 경로내의 길들은 다른 경로의 포함될 수 없다.(즉, 1번만 사용가능하다.)
🔍 풀이 방법
최대 유량
가상의 역방향 간선을 생각하는 에드워드 카프 알고리즘을 통해 구현
BFS를 구현하는 것과 유사하게 구현하되 추가 작업이 필요했다.
먼저 prev라는 배열에 특정 노드에 올때 거쳐온 간선을 저장했다.
이를 i라고 한다면 i ^ 1은 역방향 간선이 되는 것이다.
BFS를 진행하면서 목적지 노드에 도달할 수 있다면 간선의 weight를 수정한다.
거꾸로 거슬러 올라가면서 정방향은 -1, 역방향은 +1을 해준다.
이를 목적지 노드에 도착할 수 없을때까지 반복하면 된다.
⏳ 회고
최대 유량이라는 알고리즘에 흥미가 생겨서 좀 알아봤는데 재미있었다.
특히 idx와 idx ^ 1은 0과 1, 2와 3, 4와 5 ... 를 서로 참조하고 있을 수 있다는 아이디어에서 초기 인접 리스트에 간선을 넣는 방식과 일치시키면 정방향과 역방향 간선을 서로 참조할 수 있어서 간편했다.