Language: C++

vl graph[5005];
vector<bool> visited(5005);
vl ans;
void dfs(ll root) {
    for(auto num: graph[root]) {
        if(!visited[num]) {
            visited[num] = true;
            ans.pb(num);
            dfs(num);
        }
    }
}
int main() {
    ll n, from, to;
    vl indeg(5005), odeg(5005);
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> to;
        graph[i].pb(to);
        ++indeg[to];
        ++odeg[i];
    }
    bool mn = false;
    for(ll i = 1; i <= n; ++i) {
        ans.clear();
        if(!visited[i]) {
            ans.pb(i);
            visited[i] = true;
            dfs(i);
        }
        bool ex = true;
        for(auto num: ans) {
            if(indeg[num] != 1 && odeg[num] != 1) {
                ex = false;
                break;
            }
        }
//        for(auto num: ans)
//            cout << num << " ";
//        cout << "\n";
        if(ans.size() != 3)
            ex = false;
        if(ex) {
            mn = true;
            break;
        }
    }
    if(mn)
        cout << "YES";
    else
        cout << "NO";
    cout << "\n";
}

Compiler output:
a.cc:1:1: error: 'vl' does not name a type
    1 | vl graph[5005];
      | ^~
a.cc:2:1: error: 'vector' does not name a type
    2 | vector<bool> visited(5005);
      | ^~~~~~
a.cc:3:1: error: 'vl' does not name a type
    3 | vl ans;
      | ^~
a.cc:4:6: error: variable or field 'dfs' declared void
    4 | void dfs(ll root) {
      |      ^~~
a.cc:4:10: error: 'll' was not declared in this scope
    4 | void dfs(ll root) {
      |          ^~
a.cc: In function 'int main()':
a.cc:14:5: error: 'll' was not declared in this scope
   14 |     ll n, from, to;
      |     ^~
a.cc:15:5: error: 'vl' was not declared in this scope
   15 |     vl indeg(5005), odeg(5005);
      |     ^~
a.cc:16:5: error: 'cin' was not declared in this scope
   16 |     cin >> n;
      |     ^~~
a.cc:16:12: error: 'n' was not declared in this scope
   16 |     cin >> n;
      |            ^
a.cc:18:16: error: 'to' was not declared in this scope
   18 |         cin >> to;
      |                ^~
a.cc:19:9: error: 'graph' was not declared in this scope
   19 |         graph[i].pb(to);
      |         ^~~~~
a.cc:20:11: error: 'indeg' was not declared in this scope
   20 |         ++indeg[to];
      |           ^~~~~
a.cc:21:11: error: 'odeg' was not declared in this scope
   21 |         ++odeg[i];
      |           ^~~~
a.cc:24:11: error: expected ';' before 'i'
   24 |     for(ll i = 1; i <= n; ++i) {
      |           ^~
      |           ;
a.cc:24:19: error: 'i' was not declared in this scope
   24 |     for(ll i = 1; i <= n; ++i) {
      |                   ^
a.cc:25:9: error: 'ans' was not declared in this scope
   25 |         ans.clear();
      |         ^~~
a.cc:26:13: error: 'visited' was not declared in this scope
   26 |         if(!visited[i]) {
      |             ^~~~~~~
a.cc:29:13: error: 'dfs' was not declared in this scope
   29 |             dfs(i);
      |             ^~~
a.cc:33:16: error: 'indeg' was not declared in this scope
   33 |             if(indeg[num] != 1 && odeg[num] != 1) {
      |                ^~~~~
a.cc:33:35: error: 'odeg' was not declared in this scope
   33 |             if(indeg[num] != 1 && odeg[num] != 1) {
      |                                   ^~~~
a.cc:49:9: error: 'cout' was not declared in this scope
   49 |         cout << "YES";
      |         ^~~~
a.cc:51:9: error: 'cout' was not declared in this scope
   51 |         cout << "NO";
      |         ^~~~
a.cc:52:5: error: 'cout' was not declared in this scope
   52 |     cout << "\n";
      |     ^~~~