QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#217699 | #5455. TreeScript | tien_noob | WA | 7ms | 8404kb | C++20 | 1.0kb | 2023-10-17 10:36:50 | 2023-10-17 10:36:50 |
Judging History
answer
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
using namespace std;
const int N = 2e5;
vector<int> adj[N + 1];
int res, n;
void read()
{
cin >> n;
for (int i = 0; i <= n; ++ i)
{
adj[i].clear();
}
for (int i = 1; i <= n; ++ i)
{
int p;
cin >> p;
adj[p].push_back(i);
}
}
void DFS(int u, int cnt)
{
cnt += (adj[u].size() > 1);
res = max(res, cnt);
for (int v : adj[u])
{
DFS(v, cnt);
}
}
void solve()
{
res = 1;
DFS(0, 0);
cout << res << '\n';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
//freopen(TASK".OUT", "w", stdout);
}
int t = 1;
bool typetest = true;
if (typetest)
{
cin >> t;
}
for (int __ = 1; __ <= t; ++ __)
{
//cout << "Case " << __ << ": ";
read();
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 8404kb
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
Wrong Answer
time: 7ms
memory: 8380kb
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 ...
output:
8 8 3 7 5 6 9 8 7 9 8 9 12 8 4 5 8 12 4 10 11 3 8 8 8 6 10 6 7 9 1 11 8 5 9 6 5 7 5 7 8 6 8 4 6 9 9 10 7 7 6 3 9 8 10 8 5 8 6 9 11 9 3 8 8 5 6 7 10 7 10 8 10 6 9 11 2 4 8 1 1 8 12 7 6 5 8 11 9 10 10 10 6 7 4 5 9 4 9 8 12 9 11 9 9 10 5 5 10 5 8 7 5 5 9 7 4 4 6 11 4 8 3 9 5 7 7 4 10 7 15 5 7 6 8 3 10 ...
result:
wrong answer 1st numbers differ - expected: '4', found: '8'