[20260227] BOJ / P3 / 도시 왕복하기 2 / 권혁준#1977
Merged
ShinHeeEul merged 1 commit intomainfrom Feb 27, 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
🧭 풀이 시간
45분
👀 체감 난이도
✏️ 문제 설명
정점 N개 간선 P개인 무방향 그래프가 존재한다.
1번 도시와 2번 도시 사이를 왕복할 수 있는 최대 횟수를 구해보자.
단, 1,2번 도시를 제외한 다른 도시들은 여러 번 방문할 수 없다.
🔍 풀이 방법
무방향 그래프이기 때문에 1번 도시에서 2번 도시로 가는 겹치지 않는 경로의 최대 개수를 구하려고 시도했다.
-> 최대 유량을 구해 해결할 수 있지만, 도시를 중복 방문하지 않도록 추가적인 처리가 필요하다.
따라서, 정점 i의 클론 정점을 i+N으로 두고 i번 정점은 in 전용, i+N번 정점은 out 전용으로 관리했다.
다시 말하면, 간선 (u,v)에 대해 이를 용량이 1인 두 개의 간선 (u+N, v), (v+N, u)로 쪼갰다.
원래 정점에서 클론 정점으로 향하는 간선 (i, i+N)도 용량 1로 설정해주고, (1, 1+N)과 (2, 2+N)에 대해서만 예외로 용량을 INF로 설정해 주었다.
이후는 일반적인 디닉 알고리즘으로 해결했다.
⏳ 회고
강현이 덕분에 새로운 걸 배워서 좋았음