算法实现/图/深度优先搜索
外观
用 C++
/*
Depth-first search
running time is O(|E|+|V|)
g - adjacency list
used - bool array, to check if node is visited
vector<vector<int>> g;
vector<bool> used;
void dfs(int v) {
used[v] = true;
// ...
for (int &to:g[v]) {
//...
if(!used[to])
dfs(to);
}
}