QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#138534 | #5455. TreeScript | ammardab3an# | TL | 4ms | 26912kb | C++17 | 740b | 2023-08-11 21:58:14 | 2023-08-11 21:58:16 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 1e6 + 10, MM = 1e9 + 7, MAX = 1e18;
vector<ll>v[N];
int dfs(int i) {
vector<ll>vv;
for (auto x : v[i]) {
vv.emplace_back(dfs(x));
}
sort(vv.begin(), vv.end());
ll mx = 1;
if (vv.size())mx = max(mx, vv[0]);
if (vv.size()>1)mx = max(mx, vv[1] + 1);
return mx;
}
int solve() {
int n; cin >> n;
for (int i = 1; i <= n; i++) {
int p; cin >> p;
v[p].emplace_back(i);
}
cout << dfs(1) << '\n';
return 0;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
int i = 1;
while (t--) {
//cout << "case " << i << ": ";
solve();
}
return 0;
}
/*
*/
详细
Test #1:
score: 100
Accepted
time: 4ms
memory: 26912kb
input:
2 3 0 1 2 7 0 1 2 2 1 4 1
output:
1 2
result:
ok 2 number(s): "1 2"
Test #2:
score: -100
Time Limit Exceeded
input:
1000 197 0 1 1 2 1 4 1 5 8 3 5 1 4 7 12 14 4 7 10 9 12 11 16 10 21 19 22 17 25 13 28 9 5 15 26 26 33 25 15 1 35 6 32 17 37 8 19 43 19 27 29 9 30 6 31 27 35 35 37 13 28 38 57 31 38 8 22 14 33 9 18 62 52 37 10 19 22 60 54 12 38 59 64 65 80 82 28 60 85 78 27 25 71 14 52 6 59 14 87 32 33 41 59 41 88 38 ...