Submission #503739

# Submission time Handle Problem Language Result Execution time Memory
503739 2022-01-08T19:22:31 Z Newtech66 Cat in a tree (BOI17_catinatree) C++17
51 / 100
310 ms 524292 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];
        }
    }
    for(auto v:g[u])
    {
        if(v==p)    continue;
        dp[u][d]+=dp[v][d-1];
    }
    int mx=dp[u][d];
    for(int x=d-1;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+1,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 3 ms 4940 KB Output is correct
2 Correct 2 ms 4940 KB Output is correct
3 Correct 2 ms 4940 KB Output is correct
4 Correct 2 ms 4940 KB Output is correct
5 Correct 2 ms 4940 KB Output is correct
6 Correct 2 ms 4940 KB Output is correct
7 Correct 2 ms 4940 KB Output is correct
8 Correct 2 ms 4940 KB Output is correct
9 Correct 2 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 2 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 2 ms 4940 KB Output is correct
14 Correct 2 ms 4940 KB Output is correct
15 Correct 2 ms 4940 KB Output is correct
16 Correct 2 ms 4940 KB Output is correct
17 Correct 2 ms 4940 KB Output is correct
18 Correct 2 ms 4940 KB Output is correct
19 Correct 2 ms 4940 KB Output is correct
20 Correct 2 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 2 ms 4940 KB Output is correct
3 Correct 2 ms 4940 KB Output is correct
4 Correct 2 ms 4940 KB Output is correct
5 Correct 2 ms 4940 KB Output is correct
6 Correct 2 ms 4940 KB Output is correct
7 Correct 2 ms 4940 KB Output is correct
8 Correct 2 ms 4940 KB Output is correct
9 Correct 2 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 2 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 2 ms 4940 KB Output is correct
14 Correct 2 ms 4940 KB Output is correct
15 Correct 2 ms 4940 KB Output is correct
16 Correct 2 ms 4940 KB Output is correct
17 Correct 2 ms 4940 KB Output is correct
18 Correct 2 ms 4940 KB Output is correct
19 Correct 2 ms 4940 KB Output is correct
20 Correct 2 ms 4940 KB Output is correct
21 Correct 12 ms 11212 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Correct 4 ms 4940 KB Output is correct
24 Correct 3 ms 4996 KB Output is correct
25 Correct 3 ms 5024 KB Output is correct
26 Correct 3 ms 5012 KB Output is correct
27 Correct 3 ms 5068 KB Output is correct
28 Correct 3 ms 5196 KB Output is correct
29 Correct 3 ms 5140 KB Output is correct
30 Correct 3 ms 5160 KB Output is correct
31 Correct 3 ms 5324 KB Output is correct
32 Correct 3 ms 5068 KB Output is correct
33 Correct 3 ms 5196 KB Output is correct
34 Correct 3 ms 5144 KB Output is correct
35 Correct 3 ms 5196 KB Output is correct
36 Correct 3 ms 5196 KB Output is correct
37 Correct 3 ms 5152 KB Output is correct
38 Correct 4 ms 5444 KB Output is correct
39 Correct 3 ms 5536 KB Output is correct
40 Correct 3 ms 5196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 2 ms 4940 KB Output is correct
3 Correct 2 ms 4940 KB Output is correct
4 Correct 2 ms 4940 KB Output is correct
5 Correct 2 ms 4940 KB Output is correct
6 Correct 2 ms 4940 KB Output is correct
7 Correct 2 ms 4940 KB Output is correct
8 Correct 2 ms 4940 KB Output is correct
9 Correct 2 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 2 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 2 ms 4940 KB Output is correct
14 Correct 2 ms 4940 KB Output is correct
15 Correct 2 ms 4940 KB Output is correct
16 Correct 2 ms 4940 KB Output is correct
17 Correct 2 ms 4940 KB Output is correct
18 Correct 2 ms 4940 KB Output is correct
19 Correct 2 ms 4940 KB Output is correct
20 Correct 2 ms 4940 KB Output is correct
21 Correct 12 ms 11212 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Correct 4 ms 4940 KB Output is correct
24 Correct 3 ms 4996 KB Output is correct
25 Correct 3 ms 5024 KB Output is correct
26 Correct 3 ms 5012 KB Output is correct
27 Correct 3 ms 5068 KB Output is correct
28 Correct 3 ms 5196 KB Output is correct
29 Correct 3 ms 5140 KB Output is correct
30 Correct 3 ms 5160 KB Output is correct
31 Correct 3 ms 5324 KB Output is correct
32 Correct 3 ms 5068 KB Output is correct
33 Correct 3 ms 5196 KB Output is correct
34 Correct 3 ms 5144 KB Output is correct
35 Correct 3 ms 5196 KB Output is correct
36 Correct 3 ms 5196 KB Output is correct
37 Correct 3 ms 5152 KB Output is correct
38 Correct 4 ms 5444 KB Output is correct
39 Correct 3 ms 5536 KB Output is correct
40 Correct 3 ms 5196 KB Output is correct
41 Correct 58 ms 22500 KB Output is correct
42 Correct 39 ms 14216 KB Output is correct
43 Correct 54 ms 20524 KB Output is correct
44 Correct 77 ms 32984 KB Output is correct
45 Correct 102 ms 51780 KB Output is correct
46 Correct 94 ms 23592 KB Output is correct
47 Correct 144 ms 51772 KB Output is correct
48 Correct 199 ms 83044 KB Output is correct
49 Correct 310 ms 177068 KB Output is correct
50 Correct 34 ms 14540 KB Output is correct
51 Correct 42 ms 17580 KB Output is correct
52 Correct 49 ms 19276 KB Output is correct
53 Correct 67 ms 23968 KB Output is correct
54 Correct 94 ms 30284 KB Output is correct
55 Correct 99 ms 33320 KB Output is correct
56 Correct 3 ms 5196 KB Output is correct
57 Correct 218 ms 174512 KB Output is correct
58 Runtime error 258 ms 524292 KB Execution killed with signal 9
59 Halted 0 ms 0 KB -