usingnamespace std; constint N = 1e5 + 10; int n; bool st[N]; vector<int> A[N]; bool flag; string s; voiddfs(int k){ if (st[k]) return; st[k] = true; s += " " + to_string(k); for (auto kk : A[k]) { if (!st[kk]) { dfs(kk); } } }
intmain() { int n; cin >> n; int kk = 0; for (int i = 1; i <= n; i++) { int k; cin >> k; if (k) A[k].push_back(i); else kk = i; }
for (int i = 1; i <= n; i++) { sort(A[i].begin(), A[i].end()); } int ans = 0; for (int i = 1; i <= n; i++) { int res = A[i].size(); if (res != 0) { if (ans == 0) ans = res; elseif (ans != res) { flag = true; ans = max(ans, res); } } }