문제) 백준 - DFS - 작업
https://www.acmicpc.net/problem/21937
21937번: 작업
민상이가 작업할 개수 $N$와 작업 순서 정보의 개수 $M$이 공백으로 구분되어 주어진다. 두 번째줄부터 $M + 1$ 줄까지 작업 $A_i$와 작업 $B_i$가 공백으로 구분되어 주어진다. 이때 두 값의 의미는 작
www.acmicpc.net
깊이 우선 탐색을 통해 먼저 끝내야 할 작업의 수를 계산합니다. 그래프를 저장할 때 역순으로 저장하여 탐색을 진행합니다.
C++ 소스코드)
This file contains 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
int dfs(int x){ | |
visited[x] = true; | |
int res = 1; | |
for(int next: graph[x]){ | |
if(!visited[next]) | |
res += dfs(next); | |
} | |
return res; | |
} |
Full Code)
https://github.com/Chocochip101/BOJ_Solution/blob/main/Solution/21937_%EC%9E%91%EC%97%85.cpp
GitHub - Chocochip101/BOJ_Solution: BOJ Solutions
BOJ Solutions. Contribute to Chocochip101/BOJ_Solution development by creating an account on GitHub.
github.com
반응형
'PS(Problem Solving) > 백준_BOJ' 카테고리의 다른 글
[백준] 18353번 - 병사 배치하기 (C++) 문제 및 풀이 (0) | 2022.02.16 |
---|---|
[백준] 2160번 - 그림 비교 (C++) 문제 및 풀이 (0) | 2022.02.16 |
[백준] 19583번 - 싸이버개강총회 (Python) 문제 및 풀이 (0) | 2022.02.15 |
[백준] 20207번 - 달력 (C++) 문제 및 풀이 (0) | 2022.02.14 |
[백준] 21939번 - 문제 추천 시스템 Version 1 (C++) 문제 및 풀이 (0) | 2022.02.14 |
댓글