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/9466
🧭 풀이 시간
60분
👀 체감 난이도
✏️ 문제 설명
프로젝트를 하기 위해서 n명의 인원들이 서로 원하는 인원을 각가 한 명만 선택함. 이때 사이클을 형성하게 되면 그 인원들은 팀이 됨. 이때 팀을 형성하지 않는 인원의 수를 출력
🔍 풀이 방법
DFS라고는 되어있는데 그냥 풀었음. 풀고 나니까 DFS같이 생기긴함.

인원들이 모두 각각 하나의 인원만 가리킬 수 있기 때문에 접근한 경우 바로 방문처리해주었고
반복문이 종료된 후 접근하려는 인원이 리스트에 있는지 없는지를 확인해서 팀을 만들지 못한 인원을 구했음.
예를 들어 4 -> 7 -> 8 -> 1 -> 6 -> 9 순서로 접근하고 9가 가리키는 인원이 이미 방문한 인원이라 반복문을 탈출했다고 한다면 리스트내에 없으므로 접근한 모든 인원들은 팀을 만들지 못한것.
근데 9가 8을 가리키고 있어서 반복문을 탈출했다면 아래와 같음
⏳ 회고
알고리즘 안보고 푸니까 오래걸리긴 하는데 뿌듯하긴 하다.