不用dfs解
=====
a=int(input())
b=[ i for i in range(a)]
c=list(map(int,input().split()))
d=list(zip(b,c))
d=list(map(list,d))
#print(d)
"""
[(0, 4), (1, 7), (2, 2), (3, 9),
(4, 6), (5, 0), (6, 8), (7, 1), (8, 5), (9, 3)]
"""
ans=0
for i in d:
if i[-1]==-1:#
continue
t=[]
tt=-1
t.append(i)
tt=i[1]
while 1:
if i[0]==i[1]:
#print('if' ,d[i[0]])
d[i[0]].append(-1)
# print('if' ,d[i[0]])
break
# print(t)
tt=d[tt][1]
t.append(d[tt])
if t[0][0]==t[-1][1]:
# print(t)
for i in t:
d[i[1]].append(-1)
d[i[0]].append(-1)
# print('d',d,"ans",ans)
break
ans+=1
# print('------')
print(ans)