Submission #503737

# Submission time Handle Problem Language Result Execution time Memory
503737 2022-01-08T19:03:33 Z Newtech66 Cat in a tree (BOI17_catinatree) C++17
0 / 100
4 ms 4940 KB
#include<bits/stdc++.h>
using namespace std;
using lol=long long int;
#define endl "\n"
const lol mod1=1e9+7,mod2=998244353;
const lol inf=1e18+8;
const double eps=1e-12;
const double PI=acos(-1.0);
const int N=2e5+5;
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
typedef tree<pair<int,int>,null_type,less<pair<int,int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<vector<int> > g(N);
vector<vector<int> > dp;

void dfs(int u,int d,int p=-1)
{
    dp[u][0]=1;
    for(auto v:g[u])
    {
        if(v==p)    continue;
        dfs(v,d,u);
        dp[u][0]+=dp[v][d-1];
    }
    for(int x=1;x<=d/2;x++)
    {
        int mx=-1e9;
        int S=0;
        for(auto v:g[u])
        {
            if(v==p)    continue;
            S+=dp[v][d-x-1];
            mx=max(mx,dp[v][x-1]-dp[v][d-x-1]);
        }
        dp[u][x]=S+mx;
    }
    for(int x=d/2+1;x<d;x++)
    {
        for(auto v:g[u])
        {
            if(v==p)    continue;
            dp[u][x]+=dp[v][x-1];
        }
    }
    int mx=dp[u][d-1];
    for(int x=d-2;x>=0;x--)
    {
        mx=max(dp[u][x],mx);
        dp[u][x]=mx;
    }
}

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int _=1;
//cin>>_;
while(_--)
{
    int n,d;
    cin>>n>>d;
    dp.resize(n);
    for(int i=0;i<n;i++)    dp[i].resize(d,0);
    for(int i=1;i<n;i++)
    {
        int x;
        cin>>x;
        g[x].push_back(i);
        g[i].push_back(x);
    }
    dfs(0,d);
    cout<<dp[0][0];
}
return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 2 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Incorrect 4 ms 4940 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 2 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Incorrect 4 ms 4940 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 2 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Incorrect 4 ms 4940 KB Output isn't correct
8 Halted 0 ms 0 KB -