Advertisement
Ankit_132

A

Apr 29th, 2024
575
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5.     int tst;
  6.     cin>>tst;
  7.    
  8.     while(tst--){
  9.         int n;
  10.         cin>>n;
  11.        
  12.         vector<int> p(n);
  13.         for(auto &e: p)     cin>>e;
  14.        
  15.         int ans = 3;
  16.        
  17.         for(int i=0; i<n; i++){
  18.             if(p[p[i]-1]==i+1)      ans = 2;
  19.         }
  20.        
  21.         cout<<ans<<"\n";
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement