Submission #520195

# Submission time Handle Problem Language Result Execution time Memory
520195 2022-01-28T19:01:47 Z Yazan_Alattar Cat in a tree (BOI17_catinatree) C++14
11 / 100
19 ms 18252 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <utility>
#include <cmath>
#include <numeric>
#include <assert.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 2007;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

vector <int> adj[M];
ll n, d, dp[M][M], sum[M];

void dfs(int node)
{
    for(auto i : adj[node]) dfs(i);
    for(int i = 0; i <= d; ++i) sum[i] = 0;
    for(auto i : adj[node]){
        for(int j = 1; j <= d; ++j){
            sum[j] += dp[i][j - 1];
            dp[node][j] = max(dp[node][j], dp[i][j - 1]);
        }
    }
    for(int j = 1; j < d; ++j){
        if(2 * d - 2 * j < d) break;
        for(auto i : adj[node]){
            dp[node][j] = max(dp[node][j], sum[d - j] - dp[i][d - j - 1] + dp[i][j - 1]);
        }
    }
    dp[node][0] = 1 + sum[d];
    for(int i = d; i >= 0; --i) dp[node][i] = max(dp[node][i], dp[node][i + 1]);
    return;
}

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> d;
    assert(d <= n);
    d = min(d, n + 5);
    for(int i = 2; i <= n; ++i){
        int x;
        cin >> x;
        adj[x + 1].pb(i);
    }
    dfs(1);
    cout << dp[1][0] << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 19 ms 18252 KB Output is correct
22 Correct 1 ms 2380 KB Output is correct
23 Correct 1 ms 2380 KB Output is correct
24 Correct 1 ms 2380 KB Output is correct
25 Correct 2 ms 4384 KB Output is correct
26 Correct 3 ms 4428 KB Output is correct
27 Correct 2 ms 4428 KB Output is correct
28 Incorrect 4 ms 6508 KB Output isn't correct
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 19 ms 18252 KB Output is correct
22 Correct 1 ms 2380 KB Output is correct
23 Correct 1 ms 2380 KB Output is correct
24 Correct 1 ms 2380 KB Output is correct
25 Correct 2 ms 4384 KB Output is correct
26 Correct 3 ms 4428 KB Output is correct
27 Correct 2 ms 4428 KB Output is correct
28 Incorrect 4 ms 6508 KB Output isn't correct
29 Halted 0 ms 0 KB -