Problem: The Kingdom of Takahashi has N towns, numbered 1 through N.  There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i.  Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there.  Help the king by writing a program that answers this question.

Submission attempts (in order):
n,k=map(int,input().split())
A=list(map(int,input().split()))
A=[0]+A
B=[]
C=[0]+[-1]*n
now_city=1
seen=set()


for i in range(1,len(A)):
    print("Baah")


n,k=map(int,input().split())
A=list(map(int,input().split()))
A=[0]+A
B=[]
C=[0]+[-1]*n
now_city=1
seen=set()


for i in range(1,len(A)):
    print("Baah")
    if now_city in B:
        route=B[C[now_city]-1:i-1]
        break
    B.append(now_city)
    C[now_city]=i

n,k=map(int,input().split())
A=list(map(int,input().split()))
A=[0]+A
B=[]
C=[0]+[-1]*n
now_city=1
seen=set()


for i in range(1,len(A)):
    now_city=A[now_city]
    
    #if now_city in B:
        #route=B[C[now_city]-1:i-1]
    #    break
    B.append(now_city)
    C[now_city]=i
if k <= len(B):
    print(B[k-1])
else:
    k = k- len(B)
    
    if x ==0:
        #print(route[-1])
    else:
        #print(route[x-1])

n,k=map(int,input().split())
A=list(map(int,input().split()))
A=[0]+A
B=[]
C=[0]+[-1]*n
now_city=1
seen=set()


for i in range(1,len(A)):
    print("Baah")
    if now_city in B:
        route=B[C[now_city]-1:i-1]
        break

n,k=map(int,input().split())
A=list(map(int,input().split()))
A=[0]+A
B=[]
C=[0]+[-1]*n
now_city=1
seen=set()


for i in range(1,len(A)):
    print("Baah")
if k <= len(B):
    print("Baah")
else:
    k = k- len(B)
    
    if x ==0:
        print("Baah")
    else:
        print("Baah")

n,k=map(int,input().split())
A=list(map(int,input().split()))
A=[0]+A
B=[]
C=[0]+[-1]*n
now_city=1
seen=set()
 

for i in range(1,len(A)):
    now_city=A[now_city]

n,k=map(int,input().split())
A=list(map(int,input().split()))
A=[0]+A
B=[]
C=[0]+[-1]*n
now_city=1
seen=set()


for i in range(1,len(A)):
    now_city=A[now_city]
    
    #if now_city in B:
    #    route=B[C[now_city]-1:i-1]
    #    break
    B.append(now_city)
    C[now_city]=i
if k <= len(B):
    print(B[k-1])
else:
    k = k- len(B)
    x = k % len(route)
    if x ==0:
        print(route[-1])
    else:
        print(route[x-1])


n,k=map(int,input().split())
A=list(map(int,input().split()))
A=[0]+A
B=[]
C=[0]+[-1]*n
now_city=1
seen=set()
 

for i in range(1,len(A)):
    now_city=A[now_city]
    
    if now_city in B:
        route=B[C[now_city]-1:i-1]
        break
    B.append(now_city)

n,k=map(int,input().split())
A=list(map(int,input().split()))
A=[0]+A
B=[]
C=[0]+[-1]*n
now_city=1
seen=set()
 

for i in range(1,len(A)):
    now_city=A[now_city]
    
    if now_city in B:
        route=B[C[now_city]-1:i-1]
        break
    B.append(now_city)
    C[now_city]=i

n,k=map(int,input().split())
A=list(map(int,input().split()))
A=[0]+A
B=[]
C=[0]+[-1]*n
now_city=1
seen=set()


for i in range(1,len(A)):
    print("Baah")
    if now_city in B:
        print("Waah")

n,k = map(int,input().split())
s = list(map(int,input().split()))
# print(s)
now_city = 1
s_l_city = 1
t = [0] 
f = [0] 
a=0
b = 0
f_l=0


for i in range(n):
    t.append(0)
    f.append(-1)
# print(s)
sycle = 0

for i in range(1,n+10):
    now_city = s[now_city-1]

    if t[now_city-1]==1:
        #  print(i,f[j])
         sycle=i-f[now_city-1]
         f_l=f[now_city-1]
        #  f_l=i
        #  a = 1
         b = i
        #  s_l_city=now_city
        
         break
    t[now_city-1]+=1
    f[now_city-1]=i
# print(t)
# print(f_l)
# print(f_l,sycle,s_l_city)

if k>b:
    # now_city=s_l_city
    for _ in range((k-f_l)%sycle):

        now_city = s[now_city-1]
    # print((k-f_l)%sycle)
    print(now_city)
else:
    
    now_city=1
    for _ in range(k):
        now_city=s[now_city-1]
    print(now_city)


Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Accepted