Problem p02684 (python)

Fixed submission:
from sys import stdin
import numpy as np
 
def main():
    N, K = [int(x) for x in stdin.readline().rstrip().split()]
    A = [int(x) for x in stdin.readline().rstrip().split()]
    X = 1
    L = [1]
    if A[0] == 1:
        print(1)
        exit()
    if N >= K :
        for i in range(K):
            X = A[X-1]
        print(X)
        exit()
    else:
        for i in range(N):
            X = A[X-1]
            L += [X]
        #print('L',L)#OK
        C = np.zeros(N)
        for i in range(N):
            if C[L[i]-1] == 0:
                C[L[i]-1] += 1
                #print('C,i',C,i)
            else:
                break
        #print('C',C)
        #print('i+1',i+1)#Roop 回数　When Roop Goal
        #print('L[i+1]',L[i+1])#Roop initial Number
        S = L.index(L[i+1])
        #print('S',S)#When Roop Start ,Roop times
        #print(K - i-1)#Remain K
        #print('i + 1 -S',i + 1 - S)#Roop Cycle
        K = (K - i-1)%(i+1 - S)
        #print(K)
        print(L[S+K])
        
main()

Buggy submission (verdict: Runtime Error):
from sys import stdin
def main():
    N, K = [int(x) for x in stdin.readline().rstrip().split()]
    A = [int(x) for x in stdin.readline().rstrip().split()]
    if A[0] == 1:
        print(1)
        exit()       
    X=1
    Log = [1]
    for i in range(K):
      X = A[X-1]
      if (X in Log) ==True:
        break
      Log += [X]
        #print(Log)
        #print(K - Log.index(X))
        #print(i - Log.index(X)+1)
    G = Log.index(X)
    K = (K - G)%(i - G + 1)
    #print(K)
    print(Log[G+K])
main()

Buggy submission (verdict: Runtime Error):
from sys import stdin
def main():
    N, K = [int(x) for x in stdin.readline().rstrip().split()]
    A = [int(x) for x in stdin.readline().rstrip().split()]
    if A[0] == 1:
        print(1)
        exit() 
    X=1
    Log = [1]
    for i in range(K):
      X = A[X-1]
      if (X in Log) ==True:
        break
      Log += [X]
        #print(Log)
        #print(K - Log.index(X))
        #print(i - Log.index(X)+1)
    K = (K - Log.index(X))%(i - Log.index(X)+1)
    #print(K)
    print(Log[Log.index(X)+K])    
main()

Buggy submission (verdict: Runtime Error):
from sys import stdin
def main():
    N, K = [int(x) for x in stdin.readline().rstrip().split()]
    A = [int(x) for x in stdin.readline().rstrip().split()]
    X = 1
    C = 0
    Log = [1]
    while C <= K:
        X = A[X-1]
        C += 1
        if (X in Log) == True:
            break
      
        Log += [X]
    
    K = (K - C)%(C - Log.index(X))

    print(Log[Log.index(X)+K])
    
main()

Buggy submission (verdict: Runtime Error):
from sys import stdin
def main():
    N, K = [int(x) for x in stdin.readline().rstrip().split()]
    A = [int(x) for x in stdin.readline().rstrip().split()]
    X = 1
    C = 0
    Log = [1]
    while C <= K:
        X = A[X-1]
        C += 1
        if (X in Log) == True:
            break
      
        Log += [X]
    
    K = (K - C)%(C - Log.index(X))
    print(Log[Log.index(X)+K])
    
main()

Buggy submission (verdict: Runtime Error):
from sys import stdin
def main():
    N, K = [int(x) for x in stdin.readline().rstrip().split()]
    A = [int(x) for x in stdin.readline().rstrip().split()]
    X = 0
    C = 0
    Log = []
    while C <= K:
        X = A[X-1]
        C += 1
        if (X in Log) == True:
            break
        Log += [X]
        
        #print(Log)
        #print('C',C)
        #print('X',X)
        
    K = (K - C + 1)%(C - Log.index(X))
    #print(K)
    print(Log[Log.index(X)+K])
    
main()

Buggy submission (verdict: Runtime Error):
from sys import stdin
def main():
    N, K = [int(x) for x in stdin.readline().rstrip().split()]
    A = [int(x)-1 for x in stdin.readline().rstrip().split()]
    X = 0
    C = 0
    Log = []
    while C <= K:
        X = A[X-1]
        C += 1
        if (X in Log) == True:
            break
        Log += [X]
        
        #print(Log)
        #print('C',C)
        #print('X',X)
        
    K = (K - C+1)%(C - Log.index(X))
    #print(K)
    print(Log[Log.index(X)+K])
    
main()