const graph = {
'A': ['B', 'C'],
'B': ['A', 'D', 'E'],
'C': ['A', 'F'],
'D': ['B'],
'E': ['B', 'F'],
'F': ['C', 'E']
};
function dfs(graph, start, visited = new Set()){
visited.add(start);
console.log(start);
for(const neigbor of graph[start]){
if(!visited.has(neigbor)){
console.log(start+'-'+neigbor);
dfs(graph, neigbor, visited);
}
}
}
A
A-B
B
B-D
D
B-E
E
E-F
F
F-C
C