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 AC
Exec Time 142 ms
Memory 32280 KB

Judge Result

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