Submission #239761

# Submission time Handle Problem Language Result Execution time Memory
239761 2020-06-17T09:07:30 Z VEGAnn Dostavljač (COCI18_dostavljac) C++14
14 / 140
269 ms 2296 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]);

            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 512 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 12 ms 768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 1024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 72 ms 1144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 1536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 140 ms 1912 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 269 ms 2296 KB Output isn't correct
2 Halted 0 ms 0 KB -