The input is a DAG, so a visited set is not merely unnecessary here — it is wrong. It silently drops every path that would have gone through a node some earlier path already used. Flip the toggle and watch the answers disappear one at a time.
visited set incorrectly drops valid paths. Only path state (path.add / path.removeLast) is needed.
"Because the graph is a Directed Acyclic Graph (DAG), any path moving along directed edges can never cycle back to an earlier vertex. Cycle guards are mathematically impossible to trigger."
"If you use a standard boolean[] visited that marks nodes without unmarking them, discovering path A → B → D will mark B as seen, permanently blocking any later path C → B → D!"
"The path list is mutable. Maintain the invariant: push $v$ into path before recursing into $v$, and execute path.remove(path.size() - 1) immediately upon returning."
"In the worst-case complete DAG, there are $2^{n-2}$ distinct paths, each of length up to $n$. Time and space are $O(2^n \cdot n)$, which is asymptotically optimal because every single path must be constructed and output."
path.removeLast().