Initial commit

This commit is contained in:
2025-03-14 22:39:32 +08:00
commit 7b1e0f329e
38 changed files with 1153 additions and 0 deletions

33
test99-3-4.cpp Normal file
View File

@@ -0,0 +1,33 @@
// lanqiao182 小朋友崇拜圈
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, a[N], dfn[N], idx, mindfn;
int dfs(int x){
dfn[x] = ++idx;
if(dfn[a[x]]){
if(dfn[a[x]] >= mindfn) return dfn[x] - dfn[a[x]] + 1;
return 0;
}
return dfs(a[x]);
}
int main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
int ans = 0;
for(int i = 1; i <= n; i++){
if(!dfn[i]){
mindfn = idx + 1;
ans = max(ans, dfs(i));
}
}
cout << ans << endl;
return 0;
}
/* test samples
9
3 4 2 5 3 8 4 6 9
*/