Just wow.
if (path.end()[-2]==path.end()[-1]) path.pop_back();
Is this allowed?! I have no idea. Negative indices normally aren't allowed, but I see what you're trying to do. The standard way to write
path.end()[-1]
is
std::prev(path.end())
Now do you see the problem? Not only are you hacking to cover up your bug, your code doesn't do what you think. Which two entries contain the repeated vertex? Even if using a negative index on the
end()
iterator works, think about what your code is saying.
To find out why a vertex is repeated, use a debugger. This is a small program, so it's tempting to debug it by hand. But that's not working, so learn how to use a debugger. When you're dealing with a larger program, it's the only way to find and fix bugs.
EDIT: I'm not going to manually debug your code, but I came back to it and noticed this:
if (visited[v] == false)
Although that's legal, it's standard to simply write
if (!visited[v])