Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define loop(i,b,e) for(int i=b;i<=e;i++)
- #define reloop(i,e,b) for(int i=e;i>=b;i--)
- int find(int t[],int n,int x) {
- loop(i,1,n) {
- if (x == t[i])
- return i;
- }
- }
- const int N=5000;
- int n,t[N];
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- cin >> n;
- loop(i,1,n)
- cin >> t[i];
- loop(i,1,n) {
- if (t[t[t[i]]] == i) {
- cout << "YES";
- return 0;
- }
- }
- cout << "NO";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement