Merged
Conversation
Contributor
|
공통 조상이 뭔데 이놈아 |
Contributor
Author
이거도 리스트에 있으니깐 공부하십쇼 |
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/24889
🧭 풀이 시간
40분
👀 체감 난이도
✏️ 문제 설명
N개의 정점과 N개의 간선으로 이루어진 무방향 단순 연결 그래프가 주어진다.
차량 집단 M개는 각각 출발 도시 s[i], 도착 도시 e[i], 차량 수 w[i]로 이루어져 있고, 출발 도시에서 도착 도시까지 각 도시와 도로를 최대 한 번 사용해서 이동한다.
경로가 여러 개 존재한다면, 이용할 가능성이 있는 도로에 w[i]대의 차량이 지난다고 생각해야 한다.
각 도로를 통과할 가능성이 있는 차량의 수를 구해보자.
🔍 풀이 방법
연결 그래프인데 정점과 간선의 수가 같다 -> 사이클이 딱 하나 존재하는 그래프
여기서 사이클에 속한 간선을 하나 빼면 트리가 됨. -> 간선 하나를 따로 변수에 저장하고, 트리를 만들어준다.
어떤 차량 집단 (s, e, w)에 대해,
트리 상에서 s와 e를 잇는 경로에 사이클을 이루는 간선이 포함된다면 그 경로 + 나머지 사이클 간선까지 차량이 통과할 가능성이 있다.
포함되지 않는다면 그냥 둘 사이를 잇는 경로만 고려한다.
imos를 적용하면 모든 차량 집단에 대해 변화가 생기는 지점에만 기록해두고 마지막에 DFS 한 번만 돌아서 답을 구할 수 있다.
⏳ 회고
풀이는 금방 나왔는데 구현이 좀 많이 복잡했다.