Submission #237210

# Submission time Handle Problem Language Result Execution time Memory
237210 2020-06-05T09:10:52 Z IgorI Cat in a tree (BOI17_catinatree) C++17
51 / 100
22 ms 12416 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 2000;

int n, d;
int dp[N][2000];
int p[N];
vector<int> graph[N];

void dfs(int v)
{
    for (auto u : graph[v]) dfs(u);
    dp[v][0] = 1;
    for (auto u : graph[v]) dp[v][0] += dp[u][d - 1];
    for (int j = 1; j <= d; j++)
    {
        int allow = d - j - 1;
        int fl = 0;
        if (allow * 2 + 2 < d)
        {
            allow = (d + 1) / 2 - 1;
            fl = 1;
        }
        allow = max(allow, j - 1);
        for (auto u : graph[v])
        {
            int res = dp[u][j - 1];
            for (auto w : graph[v]) if (w != u)
                res += dp[w][allow];
            int delta = 0;
            /*if (d % 2 == 1 && fl)
            {
                for (auto w : graph[v]) if (w != u) if (allow >= j && allow + allow + 1 <= d && allow + j <= d)
                    delta = max(delta, dp[w][allow - 1] - dp[w][allow]);
            }*/
            dp[v][j] = max(dp[v][j], res + delta);
        }
    }
    for (int j = d - 1; j >= 0; j--) dp[v][j] = max(dp[v][j], dp[v][j + 1]);
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> d;
    if (d == 1) cout << n, exit(0);
    for (int i = 1; i < n; i++)
    {
        cin >> p[i];
        graph[p[i]].push_back(i);
    }
    dfs(0);
    cout << dp[0][0];
}

Compilation message

catinatree.cpp: In function 'void dfs(int)':
catinatree.cpp:22:13: warning: variable 'fl' set but not used [-Wunused-but-set-variable]
         int fl = 0;
             ^~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 5 ms 416 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 5 ms 416 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 512 KB Output is correct
21 Correct 22 ms 12416 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 6 ms 2432 KB Output is correct
24 Correct 6 ms 2432 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 7 ms 4480 KB Output is correct
27 Correct 7 ms 4480 KB Output is correct
28 Correct 8 ms 6528 KB Output is correct
29 Correct 8 ms 6528 KB Output is correct
30 Correct 8 ms 6528 KB Output is correct
31 Correct 8 ms 6656 KB Output is correct
32 Correct 8 ms 6272 KB Output is correct
33 Correct 10 ms 6400 KB Output is correct
34 Correct 8 ms 6144 KB Output is correct
35 Correct 8 ms 6144 KB Output is correct
36 Correct 8 ms 6528 KB Output is correct
37 Correct 9 ms 6400 KB Output is correct
38 Correct 10 ms 6784 KB Output is correct
39 Correct 9 ms 6912 KB Output is correct
40 Correct 8 ms 6656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 5 ms 416 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 512 KB Output is correct
21 Correct 22 ms 12416 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 6 ms 2432 KB Output is correct
24 Correct 6 ms 2432 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 7 ms 4480 KB Output is correct
27 Correct 7 ms 4480 KB Output is correct
28 Correct 8 ms 6528 KB Output is correct
29 Correct 8 ms 6528 KB Output is correct
30 Correct 8 ms 6528 KB Output is correct
31 Correct 8 ms 6656 KB Output is correct
32 Correct 8 ms 6272 KB Output is correct
33 Correct 10 ms 6400 KB Output is correct
34 Correct 8 ms 6144 KB Output is correct
35 Correct 8 ms 6144 KB Output is correct
36 Correct 8 ms 6528 KB Output is correct
37 Correct 9 ms 6400 KB Output is correct
38 Correct 10 ms 6784 KB Output is correct
39 Correct 9 ms 6912 KB Output is correct
40 Correct 8 ms 6656 KB Output is correct
41 Runtime error 6 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
42 Halted 0 ms 0 KB -