Skip to content

Instantly share code, notes, and snippets.

@stlee321

stlee321/dfs.cpp Secret

Created July 5, 2022 08:08
#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