/dfs.cpp Secret
Created
July 5, 2022 08:08
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
#include <iostream> | |
#include <vector> | |
using namespace std; | |
#define N_NODE 5 | |
vector<int> adjList[N_NODE]; | |
bool visited[N_NODE]; | |
void dfs(int here){ | |
// 방문 표시하기 | |
visited[here] = true; | |
// 연결된 다른 노드들 순회 | |
for(int there : adjList[here]){ | |
// 이미 방문한 노드라면 건너뛰기 | |
if(visited[there]) continue; | |
// 아직 방문하지 않았다면 방문하기 | |
dfs(there); | |
} | |
} | |
int main(){ | |
// 0번 노드부터 dfs하기 | |
dfs(0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment