Saleh127

Untitled

May 11th, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int t,a[10000],c,d,e,f,i,j,k,l;
  6. cin>>t;
  7. while(t--)
  8. {
  9. cin>>c;
  10. for(i=1;i<=c;i++)
  11. {
  12. cin>>a[i];
  13. }
  14. for(i=1;i<=c;i++)
  15. {
  16. d=1;
  17. e=a[i];
  18. while(i!=e)
  19. {
  20. d++;
  21. e=a[e];
  22. }
  23. printf("%d ",d);
  24. }
  25. cout<<endl;
  26. }
  27. return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment