When the adjacency list is created in a 1D vector, how can it be used like a 2D vector in the for loop for dfs.
int dfs(int node) {
int visCount = 1;
visited[node] = true;
//this part!
for (auto neighbour: graph[node]) {
if (!visited[neighbour]) {
visCount += dfs(neighbour);
}
}
return visCount;
}
Aucun commentaire:
Enregistrer un commentaire