2025年1月14日 星期二

小群體

 # 小群體

n = int(input())

s = [i for i in range(n)]

f = [int(i) for i in input().split()]


v = []


c = 0

ct = 0

while len(v)<len(s):

  tg = [s[c]]

  p = s[c]

  while p not in v:

    v.append(p)

    

    q = f[s.index(p)]

    if q not in v:

      tg.append(q)

    else:

      break

    p = q

  

  ct +=1

  while c<len(s) and s[c] in v:

    c+=1

print(ct)


# STDIN

# 10

# 4 7 2 9 6 0 8 1 5 3

# Output:

# 4

沒有留言:

張貼留言