[20260226] BOJ / P3 / 도시 왕복하기 2 / 이강현#1971
Merged
ShinHeeEul merged 1 commit intomainfrom Feb 26, 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/2316
🧭 풀이 시간
90분
👀 체감 난이도
✏️ 문제 설명
도시들이 양방향으로 연결되어있다. 도시 1과 2를 왔다갔다 할 수 있는 경우의 수를 구하자.
이때, 한번 방문했던 도시는 다시 방문할 수 없다.
🔍 풀이 방법
정점 분리, 최대 유량
하나의 정점을 입구와 출구로 나누어서 가상의 간선을 하나 만든다.
도시 왕복하기 1과는 다르게 간선들은 양방향이고 무한정 사용가능하고, 정점들을 한번만 방문 가능하기에 정점 내부에서의 간선들만 1로 가중치를 설정하고 정점 외부 간선들은 MAX로 설정한다. 이후 에드몬드 카프 알고리즘을 적용한다.
⏳ 회고
어제 풀었던 문제의 연장선이었다.
정점을 간선과 같이 바라보고 정점 내부에 간선을 만든다는 아이디어를 생각해내서 뿌듯하다.(정점 분리)
하지만 이후에 1과 2를 번갈아가는 횟수를 측정하는 문제였어서 그래프 업데이트를 어느 시점에 해야하는지를 생각하는게 어려웠다.
하지만 그래프가 양방향 간선의 형태로 존재하기 때문에 1에서 2로 독립적인 경로로 가는 경우만 생각하면 됐다.
이 부분이 처음에는 이해가 잘 안됐는데, 정점 내부에 가상의 역방향 간선을 두었고 우리는 1에서 2로 갈 수 있는 경로가 존재하면 2에서 1로 갈 수 있다는 것을 알 수 있다. 다만 중복되면 안된다는 문제 조건을 충족하기 위해 가지 못한다고 가정하는 것일 뿐, 실제로는 갈 수 있다. 따라서 1에서 2로 갈 수 있는 유니크한 경로를 모두 찾으면 그것이 왔다갔다하는 모든 경우의 수가 되는 것이다.