Problem p02684 (python)

Fixed submission:
n, k = map(int, input().split())
a = [int(i) for i in input().split()]


lst = []
visit_now = 1
visit_list = [-1] * (n + 1)
cnt = 0

while visit_list[visit_now - 1] == -1:
    visit_list[visit_now - 1] = cnt
    lst.append(visit_now)
    visit_now = a[visit_now - 1]
    cnt += 1

start = visit_list[visit_now - 1]
loop_num = cnt - start

if k <= start:
    ans = lst[k]
else:
    k -= start
    k %= loop_num
    ans = lst[start + k]

print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [int(i) for i in input().split()]


lst = []
visit_now = 1
visit_list = [0] * n

while True:
    if visit_list[visit_now - 1] == 1:
        break
    visit_list[visit_now - 1] = 1
    lst.append(visit_now)
    visit_now = a[visit_now - 1]


start = lst.index(visit_now)
loop_num = n - start - 1
# lst = lst[start:]

if k <= start:
    ans = lst[k]
else:
    k -= start
    k %= loop_num
    ans = lst[start + k]

print(ans)

Buggy submission (verdict: Runtime Error):
map(int, input().split())
a = [int(i) for i in input().split()]


lst = []
visit_now = 1
visit_list = [0] * n

while True:
    if visit_list[visit_now - 1] == 1:
        break
    visit_list[visit_now - 1] = 1
    lst.append(visit_now)
    visit_now = a[visit_now - 1]


start = lst.index(visit_now)
loop_num = n - start - 1

if k <= start:
    ans = lst[k]
else:
    k -= start
    k %= loop_num
    ans = lst[start + k]

print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [int(i) for i in input().split()]

lst = []
visit_now = 1
visit_list = [0] * n

while True:
    if visit_list[visit_now - 1] == 1:
        break
    visit_list[visit_now - 1] = 1
    lst.append(visit_now)
    visit_now = a[visit_now - 1]


start = lst.index(visit_now)
loop_num = n - start - 1

if k <= start:
    ans = lst[k]
else:
    k -= start
    k %= loop_num
    ans = lst[start + k]

print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [int(i) for i in input().split()]

lst = []
visit_now = 1
visit_list = [0] * n

while True:
    if visit_list[visit_now - 1] == 1:
        break
    visit_list[visit_now - 1] = 1
    lst.append(visit_now)
    visit_now = a[visit_now - 1]


start = lst.index(visit_now)
loop_num = n - start - 1
lst = lst[start:]

k -= start
k %= loop_num

print(lst[k])

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [int(i) for i in input().split()]


lst = []
visit_now = 1
visit_list = [0] * n

while True:
    if visit_list[visit_now - 1] == 1:
        break
    visit_list[visit_now - 1] = 1
    lst.append(visit_now)
    visit_now = a[visit_now - 1]


start = lst.index(visit_now)
loop_num = n - start - 1
lst = lst[start:]

k -= start
k %= loop_num

print(lst[k])
# print(lst, loop_num, loop_list, k)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [int(i) for i in input().split()]

lst = []
visit_now = 1

while True:
    if visit_list[visit_now - 1] == 1:
        break
    visit_list[visit_now - 1] = 1
    lst.append(visit_now)
    visit_now = a[visit_now - 1]


start = lst.index(visit_now)
loop_num = n - start - 1
lst = lst[start:]

k -= start
k %= loop_num

print(lst[k])
# print(lst, loop_num, loop_list, k)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [int(i) for i in input().split()]

lst = [1]
visit_now = 1

visit_list = [0] * n
visit_list[0] = 1
while True:
    visit_now = a[visit_now - 1]
    if visit_list[visit_now - 1] == 1:
        break
    lst.append(visit_now)


start = lst.index(visit_now)
loop_num = n - start - 1
lst = lst[start:]

k -= start
k %= loop_num

print(lst[k])
# print(lst, loop_num, loop_list, k)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [int(i) for i in input().split()]

lst = []
visit_now = 1
while not visit_now in lst:
    lst.append(visit_now)
    visit_now = a[visit_now - 1]

start = lst.index(visit_now)
loop_num = n - start - 1
loop_list = lst[start:]

k -= start
k %= loop_num

print(loop_list[k])

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [int(i) for i in input().split()]

lst = []
visit_now = 1
while not visit_now in lst:
    lst.append(visit_now)
    visit_now = a[visit_now - 1]

start = lst.index(visit_now)
loop_num = n - start - 1
loop_list = lst[start:]

k -= start
k %= loop_num

print(loop_list[k])