ABC228 B - Takahashi's Secret
解答
n,x = map(int,input().split()) a = list(map(int,input().split())) set1 = {x} ind = 0 cnt = 1 for i in range(n): if 2 <= cnt: if ind != a[ind-1]: ind = a[ind-1] set1.add(ind) cnt += 1 else: if ind != a[x-1]: ind = a[x-1] set1.add(ind) cnt += 1 print(len(set1))
一度訪れたところに行かないようにする実装方法が思い浮かばず、
今回もset()にお世話になってしまいました