Submission #481321

# Submission time Handle Problem Language Result Execution time Memory
481321 2021-10-20T11:22:27 Z DJeniUp Cat in a tree (BOI17_catinatree) C++17
0 / 100
1 ms 332 KB
//#pragma GCC Optimize("O3")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pairll;
typedef pair<ll,pairll>pairlll;
typedef pair<pairll,pairll>pairllll;
typedef long double ld;
typedef pair<ll,string>pairls;

#define INF 1000000000000007
#define MOD 1000000007
#define pb push_back
#define fr first
#define sc second
#define endl '\n'

ll n,m,t[1507][1507],res;

vector<ll>v[1507];

void S(ll x,ll y){

    for(int i=0;i<int(v[x].size());i++){
        if(v[x][i]!=y)S(v[x][i],x);
    }
    t[x][0]=1;
    for(int i=0;i<int(v[x].size());i++){
        if(v[x][i]!=y)t[x][0]+=t[v[x][i]][m-1];
    }
    for(int i=1;i<m;i++){
        if(i*2<m){
            t[x][i]=0;
            ll h=0;
            for(int j=0;j<int(v[x].size());j++){
                if(v[x][j]!=y)h+=t[v[x][j]][m-i-1];
            }
            for(int j=0;j<int(v[x].size());j++){
                if(v[x][j]!=y){
                    t[x][i]=max(t[x][i],h-t[v[x][j]][m-i-1]+t[v[x][j]][i-1]);
                }
            }
        }
    }
    return ;
}

int main() {
    
    cin>>n>>m;
    m=min(n,m);
    for(int i=1;i<n;i++){
        ll l;
        cin>>l;
        v[l].pb(i);
        v[i].pb(l);
    }
    S(0,0);
    res=0;
    for(int i=0;i<m;i++){
        res=max(res,t[0][i]);
    }
    cout<<res<<endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -