Backtracking 1 - Additional States - Backtracking / Additional States

https://algo.monster/problems/backtracking-additional-states

The template (at least for Java) seems inconsistent with the text: “we are keeping one or more additional states as dfs parameters”

But in the template (for Java), additional states are not in parameter list, can the team look into this?

Hi sea, you are right. We updated it. Thanks!

Hi , I wonder why this line of code should act like this.
// add a copy of the path to the result
res.emplace_back(std::vector(path));
why do you need to explicitly construc a new vector?
Is it necessary?

you need to make a deep copy otherwise future calls would mutate it and you end up with a result vector with each element referencing the same vector

Actually, we pass vector by value, so it is already copied on each invocation of dfs. So it is not necessary to copy it again. Also, we could move it to avoid copying into res:

res.push_back(std::move(path));

In the java version, line 9 is missing the “path” parameter.
dfs(startIndex + edge.length(), path, res, […additional states]);