Advertisement
amine99

Untitled

Feb 17th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define loop(i,b,e) for(int i=b;i<=e;i++)
  4. #define reloop(i,e,b) for(int i=e;i>=b;i--)
  5.  
  6. int find(int t[],int n,int x) {
  7.    loop(i,1,n) {
  8.       if (x == t[i])
  9.          return i;
  10.    }
  11. }
  12.  
  13. const int N=5000;
  14. int n,t[N];
  15.  
  16. int main() {
  17.    ios_base::sync_with_stdio(false);
  18.     cin.tie(0);
  19.     cout.tie(0);
  20.    cin >> n;
  21.    loop(i,1,n)
  22.       cin >> t[i];
  23.  
  24.    loop(i,1,n) {
  25.       if (t[t[t[i]]] == i) {
  26.          cout << "YES";
  27.          return 0;
  28.       }
  29.    }
  30.    cout << "NO";
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement