Day 31 (2022.2.12)
# acwing 1224. Exchange bottles
if __name__ == '__main__':
n = int(input())
arr = [0]+[int(x) for x in input().split()]
st, cnt = [0]*(n+1), 0
for i in range(1,n+1):
if not st[i]:
cnt += 1
while not st[i]:
st[i] = 1
i = arr[i]
print(n-cnt)
Address book management system
成為“黑客”前,應該掌握的“Python編程語言”最近有很多