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/15669
🧭 풀이 시간
25분
👀 체감 난이도
✏️ 문제 설명
N개의 정점으로 이루어진 트리가 있다.
이 트리에 M번의 실험을 진행했다.
각 실험에서는 트리에서 시작점과 도착점을 정해두고 시작점에 빨간색 입자를 놓은 뒤, 입자를 도착점까지 최단 경로로 보낸다.
입자는 점을 하나씩 지날 때마다 색깔이 바뀐다. (빨간색 -> 검은색, 검은색 -> 빨간색)
실험의 기록이 모두 사라졌다.
오직 특정 간선 (u, v)에 대해 u -> v 방향으로 지났었고, 도착점에서의 입자 색깔만이 남아있다.
각 실험에 대해, (시작점, 도착점) 쌍으로 가능한 경우의 수를 구해보자.
🔍 풀이 방법
[사용한 알고리즘]
일단 1번 점을 트리의 루트로 설정하고, 각 실험에서 주어진 간선 (u,v)에 대해,
만약 도착점의 입자가 빨간색이었다면?
=> 실험에 사용된 시작점, 도착점 사이의 거리가 짝수여야 한다.
도착점의 입자가 검은색이었다면?
=> 실험에 사용된 시작점, 도착점 사이의 거리가 홀수여야 한다.
rerooting으로 이 경우의 수를 쉽게 구할 수 있다.⏳ 회고
오늘부터 열심히 풀ㅇ게요..