1function eulerPath(edges, start) {
2 const adj = new Map();
3 for (const [u, v] of edges) {
4 if (!adj.has(u)) adj.set(u, []);
5 adj.get(u).push(v);
6 }
7 const stack = [start];
8 const path = [];
9 while (stack.length) {
10 const u = stack[stack.length - 1];
11 if (adj.get(u)?.length) stack.push(adj.get(u).pop());
12 else path.push(stack.pop());
13 }
14 return path.reverse();
15}