Untitled

 avatar
unknown
plain_text
6 months ago
505 B
3
Indexable
def teleport(n, teleportation_map, start, k):
    current_city = start
    for _ in range(k):
        current_city = teleportation_map[current_city - 1]
    return current_city

def main():
    # Read input
    n, q = map(int, input().split())
    teleportation_map = list(map(int, input().split()))
    
    # Process queries
    for _ in range(q):
        x, k = map(int, input().split())
        result = teleport(n, teleportation_map, x, k)
        print(result)

if __name__ == "__main__":
    main()
Editor is loading...
Leave a Comment