Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- using namespace std;
- int main()
- {
- int d,n,A[10000],T[10000],j=0,c=0;
- scanf("%d",&d);
- for(int l=0;l<d;l++)
- {
- scanf("%d",&n);
- for(int j=0;j<n;j++)
- {
- scanf("%d",&A[j]);
- T[j]=0;
- }
- for(int k=0;k<n;k++)
- {
- T[A[k]-1]++;
- }
- for(int i=0;i<n;i++)
- {
- if(T[i]==0)
- {
- j=i;
- }
- while(T[j]==0)
- {
- T[A[j]-1]--;
- j=A[j]-1;
- }
- }
- c=0;
- for(int i=0;i<n;i++)
- {
- if(T[i]!=0) c++;
- }
- printf("%d\n",c);
- c=0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement