https://www.acmicpc.net/problem/1865
N - 1번 해야함 한 번이라도 방문한 곳이라면 업데이트
음의 알고리즘이 존재하면 N번째 했을 때 업데이트가 된다.