#46459: Python優化代碼


garmakrjh@gmail.com (mma chuang)

學校 : 不指定學校
編號 : 143031
來源 : [58.99.124.10]
最後登入時間 :
2025-07-07 17:52:20

n = int(input())
friends_array = list(map(int, input().split()))
marked = [False] * n
counter = 0

for i in range(n):
    if not marked[i]:
        # 追蹤整個朋友圈,標記所有相關的人
        current = i
        while not marked[current]:
            marked[current] = True
            current = friends_array[current]
        counter += 1

print(counter)