QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#133283 | #5455. TreeScript | rootcucu | WA | 11ms | 5548kb | C++17 | 1007b | 2023-08-01 21:53:32 | 2023-08-01 21:53:35 |
Judging History
answer
#include <iostream>
using namespace std;
int par[200'007];
int nch[200'007];
int mav[200'007];
int cnt[200'007];
void solve(){
int n; cin >> n;
fill_n(nch, n, 0);
fill_n(cnt, n, 0);
fill_n(mav, n, 0);
fill_n(cnt, n, 0);
for (int i = 0; i < n; i++){
int p; cin >> p;
par[i] = p - 1;
if (p > 0)
nch[p-1]++;
}
for (int i = 0; i < n; i++){
int j = i;
while (j >= 0 && nch[j] == 0){
if (cnt[j] > 1)
mav[j]++;
int p = par[j];
if (mav[p] > mav[j]){
mav[p] = mav[j];
cnt[p] = 1;
}
else if (mav[p] == mav[j]) cnt[p] = 2;
j = par[j];
nch[j]--;
}
}
if (n == -1)
cout << "0\n";
else
cout << mav[0] + 1 << "\n";
}
int main(void){
ios::sync_with_stdio(0); cin.tie(0);
int t; cin >> t;
while (t--) solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 5508kb
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: 11ms
memory: 5548kb
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:
2 2 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 2 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 2 1 1 2 2 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 ...
result:
wrong answer 1st numbers differ - expected: '4', found: '2'