#42063: __ng


chinanmsl198964@gmail.com (120-36嚴琮傑)

學校 : 不指定學校
編號 : 277342
來源 : [111.184.224.72]
最後登入時間 :
2025-06-09 22:25:51

n = int(input())
friends = list(map(int,input().split()))
flags = 0
Visited = set()
for i in range(n):
    if i  not in Visited:
        current = i
        Cycle = set()
        while True:
            if friends[current] == i:
                Cycle.add(current)
                break
            else:
                Cycle.add(current)
                current = friends[current]
        flags+=1
        Visited.update(Cycle)
        
print(flags,"\n")

2024/9/23