SHARE
TWEET

Untitled

a guest Apr 25th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def calc(a):
  2.     n = len(a)
  3.     t = [0 for x in range(n)]
  4.  
  5.     for x in range(n):
  6.         t[a[x]] += 1
  7.  
  8.     for x in range(n):
  9.         d = 1
  10.         for y in range(n):
  11.             if t[y] == 0:
  12.                 t[a[y]] -= 1
  13.                 a[y] = -1
  14.                 t[y] = -1
  15.                 d = 0
  16.                 n -= 1
  17.         if d == 1:
  18.             return n
  19.     return n
  20.  
  21.  
  22. if __name__ == "__main__":
  23.     d = int(input())
  24.     ans = []
  25.  
  26.     for i in range(d):
  27.         n = int(input())
  28.         a = [int(x) - 1 for x in input().split()]
  29.  
  30.         ans.append(calc(a))
  31.  
  32.     for a in ans:
  33.         print(a)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top