QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#381606#5455. TreeScriptwsc2008WA 9ms29336kbC++141.2kb2024-04-07 19:14:332024-04-07 19:14:33

Judging History

你现在查看的是最新测评结果

  • [2024-04-07 19:14:33]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:29336kb
  • [2024-04-07 19:14:33]
  • 提交

answer

#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<ll,ll>
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define per(i,a,b) for(ll i=(a);i>=(b);--i)
using namespace std;
bool Mbe;
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void write(ll x){
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
const ll N=1e6+9;
ll T,n,dp[N];
vector<ll>to[N];
void dfs(ll x,ll f){
    vector<ll>g;
    for(ll y:to[x]){
        if(y==f)continue;
        dfs(y,x);
        g.push_back(dp[y]);
    }
    sort(g.begin(),g.end());
    dp[x]=1;
    rep(i,0,(ll)g.size()-1){
        if(i==1)dp[x]=max(dp[x],g[i]+1);
        else if(!i)dp[x]=max(dp[x],g[i]);
    }
}
void solve(){
    n=read();
    rep(i,0,n)to[i].clear();
    rep(i,1,n){
        ll x=read();
        to[x].push_back(i);
    }
    dfs(1,-1);
    write(dp[1]),putchar('\n');
}
bool Med;
int main(){
    cerr<<fabs(&Med-&Mbe)/1048576.0<<"MB\n";
    T=read();
    while(T--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 29336kb

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: 9ms
memory: 27632kb

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:

3
3
2
2
2
2
2
3
4
2
2
3
2
3
3
3
3
2
2
3
3
3
2
2
2
2
2
2
3
2
2
3
2
3
3
3
5
3
2
2
2
2
2
2
2
3
2
3
3
2
3
2
2
3
2
2
2
2
3
2
2
3
2
2
2
2
2
3
3
3
2
2
3
2
3
2
2
3
3
1
1
2
3
2
3
2
2
2
2
2
2
2
4
2
3
2
2
3
2
2
2
3
3
3
3
3
2
6
2
2
3
3
2
2
3
4
2
3
3
2
4
3
3
2
3
3
3
3
3
2
2
2
3
2
3
3
4
2
2
2
4
2
3
2
2
2
2
3
3
2
...

result:

wrong answer 1st numbers differ - expected: '4', found: '3'