yasi04

Untitled

Dec 5th, 2021
576
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def func(worlds):
  2.     f = list('0' * (len(worlds)))
  3.     b = 0
  4.     for i in range(len(f)):
  5.         if f[i] == '0':
  6.             b += 1
  7.             m = worlds[i] - 1
  8.             while f[m] != '1':
  9.                 f[m] = '1'
  10.                 m = worlds[m] - 1
  11.     return b
  12. def func2(worlds):
  13.     a = func(worlds)
  14.     if a == 1:
  15.         a = 0
  16.     return a
  17. n = int(input())
  18. worlds = list(map(int, input().split()))
  19. print(func2(worlds))
RAW Paste Data