Submission #239762

# Submission time Handle Problem Language Result Execution time Memory
239762 2020-06-17T09:11:10 Z VEGAnn Dostavljač (COCI18_dostavljac) C++14
14 / 140
313 ms 2424 KB
#include <bits/stdc++.h>
#define PB push_back
#define sz(x) ((int)x.size())
#define i3 array<int,3>
using namespace std;
typedef long double ld;
typedef long long ll;
const int N = 510;
const int M = 510;
const int K = 110;
const int T = 2010;
const int oo = 2e9;
vector<int> g[N];
int n, m, a[N], f[N][M][2], ans = 0;

int upd(int &x, int y){
    x = max(x, y);
}

void dfs(int v, int p){
//    for (int cur = m - 1; cur >= 0; cur--)
//        upd(f[v][cur + 1][0], f[v][cur][0] + a[v]);

    f[v][1][0] = a[v];

    for (int u : g[v]){
        if (u == p) continue;

        dfs(u, v);

        for (int cur = m; cur >= 0; cur--)
        for (int nw = m; nw >= 0; nw--) {
            if (cur + nw + 2 <= m) {
                upd(f[v][cur + nw + 2][0], f[v][cur][0] + f[u][nw][0]);
                upd(f[v][cur + nw + 2][0], f[v][cur][1] + f[u][nw][0]);
            }

            if (cur + nw + 1 <= m)
                upd(f[v][cur + nw + 1][1], f[v][cur][0] + max(f[u][nw][0], f[u][nw][1]));
        }
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n >> m;

    for (int i = 0; i < n; i++)
        cin >> a[i];

    for (int i = 1; i < n; i++){
        int x, y; cin >> x >> y;
        x--; y--;
        g[x].PB(y);
        g[y].PB(x);
    }

    dfs(0, -1);

    for (int kl = 0; kl <= m; kl++) {
        upd(ans, f[0][kl][0]);
        upd(ans, f[0][kl][1]);
    }

    cout << ans;

    return 0;
}

Compilation message

dostavljac.cpp: In function 'int upd(int&, int)':
dostavljac.cpp:18:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 512 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 512 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 640 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 85 ms 1144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 1536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 172 ms 2040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 313 ms 2424 KB Output isn't correct
2 Halted 0 ms 0 KB -