Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: anonymous

Problemset: เปลี่ยนมือ

Language: cpp

Time: 0.007 second

Submitted On: 2026-10-27 10:20:46

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n;cin >> n;

    vector<int> a(n+1);
    for(int i=1;i<=n;i++) cin >> a[i];

    vector<bool> v(n+1, false);
    int ans = 0;
    for(int i=1;i<=n;i++){
        if(!v[i]){
            int cn = i,cl = 0;
            while (!v[cn]){
                v[cn] = true;
                cn = a[cn];
                cl++;
            }
            ans = max(ans,cl);
        }
    }

    cout << ans;
}