Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def func(worlds):
- f = list('0' * (len(worlds)))
- b = 0
- for i in range(len(f)):
- if f[i] == '0':
- b += 1
- m = worlds[i] - 1
- while f[m] != '1':
- f[m] = '1'
- m = worlds[m] - 1
- return b
- def func2(worlds):
- a = func(worlds)
- if a == 1:
- a = 0
- return a
- n = int(input())
- worlds = list(map(int, input().split()))
- print(func2(worlds))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement