Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #include <stdio.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int d,n,A[10000],T[10000],j=0,c=0;
  7. scanf("%d",&d);
  8. for(int l=0;l<d;l++)
  9. {
  10. scanf("%d",&n);
  11. for(int j=0;j<n;j++)
  12. {
  13. scanf("%d",&A[j]);
  14. T[j]=0;
  15. }
  16. for(int k=0;k<n;k++)
  17. {
  18. T[A[k]-1]++;
  19. }
  20. for(int i=0;i<n;i++)
  21. {
  22. if(T[i]==0)
  23. {
  24. j=i;
  25. }
  26. while(T[j]==0)
  27. {
  28. T[A[j]-1]--;
  29. j=A[j]-1;
  30. }
  31. }
  32. c=0;
  33. for(int i=0;i<n;i++)
  34. {
  35. if(T[i]!=0) c++;
  36. }
  37. printf("%d\n",c);
  38. c=0;
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement