QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#685567 | #5455. TreeScript | DanRan02 | WA | 0ms | 3616kb | C++20 | 746b | 2024-10-28 20:11:36 | 2024-10-28 20:11:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int _;
cin >> _;
while (_ --) {
int n;
cin >> n;
vector<int> p(n + 1);
vector<vector<int>> adj(n + 1);
for (int i = 1; i <= n; ++ i) {
cin >> p[i];
adj[p[i]].push_back(i);
}
vector<int> dp(n + 1, 0);
auto dfs = [&](auto dfs, int u) -> void{
vector<int> v;
for (auto ne : adj[u]) {
dfs(dfs, ne);
v.push_back(ne);
}
sort(v.begin(), v.end(), greater());
if (v.size() == 0) dp[u] = 1;
else if (v.size() == 1) dp[u] = v[0];
else {
dp[u] = max(v[0], v[1] + 1);
}
};
dfs(dfs, 1);
cout << dp[1] << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3616kb
input:
2 3 0 1 2 7 0 1 2 2 1 4 1
output:
2 7
result:
wrong answer 1st numbers differ - expected: '1', found: '2'