Aaaa
let g = new Map();
g.set(1, [2,3]);
g.set(2, [1,3]);
g.set(3, []);
let path = [];
let visited = new Set();
const ip = (g, v) => {
visited.add(v);
path.push(v);
console.log("Visiting and pushing " + v);
const adj = g.get(v);
console.log("Looking at subtree " + adj);
for (var w of adj) {
console.log("going into " + w + " while path is " + path);
if (path.includes(w)) {
return true;
console.log("DOOO!");
}
ip(g, w);
}
path.pop();
console.log("path is " + path);
if (path.length === 0) return false;
}
console.log(ip(g, 1));