void dfs(Node& root, std::function<void(Node*)> f) {
std::stack<Node*> queue;
queue.push(&root);
std::unordered_set<const Node*> visited;
while (!queue.empty()) {
Node* const node = queue.top();
queue.pop();
f(node);
visited.insert(node);
for (Node* const neighbor : node->neighbors) {
if (visited.find(neighbor) == visited.end()) {
queue.push(neighbor);
}
}
}
}