Submission #13063629


Source Code Expand

Copy
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    if A[0]==1:
        print(1)
        sys.exit()
    cur_a=1
    cunt=0
    visited=[False]*n
    visited[0]=True
    route=[1]
    for _ in range(k):
        next_a=A[cur_a-1]
        if visited[next_a-1]:
            loop=len(route)-route.index(next_a)
            cunt-=loop-1
            break
        cur_a=next_a
        cunt+=1
        route.append(cur_a)
        visited[cur_a-1]=True
    else:
        print(next_a)
        sys.exit()
    #print(route)
    #rint(cunt,loop)
    k-=cunt
    k=k%loop
    #print(k)
    print(route[cunt+k])
    

if __name__=='__main__':
    main()

Submission Info

Submission Time
Task D - Teleporter
User charter
Language Python (3.8.2)
Score 400
Code Size 769 Byte
Status
Exec Time 142 ms
Memory 32280 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt
Subtask1 400 / 400 sample_01.txt, sample_02.txt, sub1_01.txt, sub1_02.txt, sub1_03.txt, sub1_04.txt, sub1_05.txt, sub1_06.txt, sub1_07.txt, sub1_08.txt, sub1_09.txt, sub1_10.txt, sub1_11.txt, sub1_12.txt, sub1_13.txt, sub1_14.txt, sub1_15.txt, sub1_16.txt, sub1_17.txt, sub1_18.txt, sub1_19.txt, sub1_20.txt, sub1_21.txt, sub1_22.txt, sub1_23.txt, sub1_24.txt, sub1_25.txt, sub1_26.txt, sub1_27.txt, sub1_28.txt, sub1_29.txt, sub1_30.txt, sub1_31.txt, sub1_32.txt, sub1_33.txt, sub1_34.txt, sub1_35.txt, sub1_36.txt, sub1_37.txt, sub1_38.txt, sub1_39.txt, sub1_40.txt, sub1_41.txt, sub1_42.txt, sub1_43.txt, sub1_44.txt, sub1_45.txt, sub1_46.txt, sub1_47.txt, sub1_48.txt, sub1_49.txt, sub1_50.txt, sub1_51.txt, sub1_52.txt, sub1_53.txt, sub1_54.txt, sub1_55.txt
Case Name Status Exec Time Memory
sample_01.txt 18 ms 8868 KB
sample_02.txt 20 ms 8972 KB
sub1_01.txt 24 ms 11820 KB
sub1_02.txt 47 ms 24224 KB
sub1_03.txt 24 ms 10820 KB
sub1_04.txt 63 ms 32012 KB
sub1_05.txt 64 ms 32176 KB
sub1_06.txt 50 ms 24580 KB
sub1_07.txt 43 ms 23548 KB
sub1_08.txt 61 ms 32012 KB
sub1_09.txt 86 ms 23096 KB
sub1_10.txt 59 ms 29348 KB
sub1_11.txt 40 ms 18288 KB
sub1_12.txt 71 ms 32008 KB
sub1_13.txt 75 ms 32168 KB
sub1_14.txt 142 ms 32236 KB
sub1_15.txt 53 ms 24524 KB
sub1_16.txt 68 ms 32272 KB
sub1_17.txt 47 ms 24568 KB
sub1_18.txt 67 ms 32124 KB
sub1_19.txt 32 ms 13208 KB
sub1_20.txt 142 ms 32272 KB
sub1_21.txt 64 ms 23556 KB
sub1_22.txt 58 ms 25876 KB
sub1_23.txt 62 ms 18944 KB
sub1_24.txt 114 ms 27728 KB
sub1_25.txt 116 ms 26824 KB
sub1_26.txt 65 ms 23184 KB
sub1_27.txt 46 ms 21900 KB
sub1_28.txt 81 ms 24452 KB
sub1_29.txt 39 ms 14524 KB
sub1_30.txt 60 ms 20624 KB
sub1_31.txt 25 ms 10012 KB
sub1_32.txt 47 ms 24172 KB
sub1_33.txt 36 ms 15196 KB
sub1_34.txt 79 ms 21808 KB
sub1_35.txt 22 ms 10116 KB
sub1_36.txt 91 ms 29632 KB
sub1_37.txt 60 ms 29608 KB
sub1_38.txt 117 ms 29976 KB
sub1_39.txt 74 ms 28784 KB
sub1_40.txt 28 ms 13236 KB
sub1_41.txt 65 ms 32236 KB
sub1_42.txt 99 ms 32128 KB
sub1_43.txt 117 ms 32116 KB
sub1_44.txt 123 ms 32280 KB
sub1_45.txt 126 ms 32012 KB
sub1_46.txt 63 ms 32280 KB
sub1_47.txt 67 ms 32172 KB
sub1_48.txt 140 ms 32164 KB
sub1_49.txt 83 ms 32232 KB
sub1_50.txt 63 ms 32008 KB
sub1_51.txt 57 ms 28484 KB
sub1_52.txt 43 ms 20940 KB
sub1_53.txt 39 ms 14396 KB
sub1_54.txt 129 ms 32168 KB
sub1_55.txt 68 ms 32176 KB