Post

DFS

DFS

1. DFS 기본 개념

깊이 우선 탐색. 시간복잡도는 O(V+E) V:정점, E:간선


2. 자주 쓰는 패턴

(1) 기본 뼈대

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
vector<int>v [1004];
bool visited[1004];

void dfs(int here)
{
    visited[here] = true;

    for(int i : v[here])
    {
        if(!visited[i])
        {
            dfs(i);
        }
    }
}


3. DFS 문제 유형별 키워드

This post is licensed under CC BY 4.0 by the author.