vector distance(n, INT64_MAX);
if (res[n] < INT64_MAX) {

What’s wrong with these lines?