Submission #701000

# Submission time Handle Problem Language Result Execution time Memory
701000 2023-02-19T16:54:34 Z Do_you_copy Dostavljač (COCI18_dostavljac) C++17
0 / 140
209 ms 4196 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back

using namespace std;
using ll = long long;
using pii = pair <int, int>;

const int maxN = 506 + 1;
const int inf = 0x3f3f3f3f;
//const int Mod =
int n, m;
int a[maxN];
vector <int> adj[maxN];

ll dp[maxN][maxN][2];
int sz[maxN];

void dfs(int u, int p){
    sz[u] = 1;
    for (int i: adj[u]){
        if (i == p) continue;
        dfs(i, u);
        sz[u] += sz[i];
        vector <ll> tem[2];
        tem[0].resize(m + 1, 0);
        tem[1].resize(m + 1, 0);
        for (int j = 0; j <= m; ++j){
            for (int k = 0; k < j; ++k){
                if (j - k > 1) tem[0][j] = max(tem[0][j], dp[u][j - k - 2][0] + dp[i][k][0]);
                tem[1][j] = max(tem[1][j], dp[u][j - k - 1][0] + dp[i][k][1]);
            }
        }
        for (int j = 0; j <= m; ++j){
            dp[u][j][0] = tem[0][j];
            dp[u][j][1] = tem[1][j];
        }
       // cerr << u << " " << i << "\n";
    }
    for (int j = m; j >= 1; --j){
        dp[u][j][0] = max(dp[u][j][0], dp[u][j - 1][0] + a[u]);
        dp[u][j][1] = max(dp[u][j][1], dp[u][j - 1][1] + a[u]);
    }
    //for (int j = 0; j <= m; ++j){
        //cerr << u << " " << j << " " << dp[u][j][0] << " " << dp[u][j][1] << "?\n";
    //}
}

void Init(){
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i < n; ++i){
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(1, 0);
    ll ans = 0;
    for (int i = 0; i <= m; ++i) ans = max(ans, dp[1][i][1]);
    cout << ans;
}

#define taskname "test"
signed main(){
    faster
    if (fopen(taskname ".inp", "r")){
        freopen(taskname ".inp", "r", stdin);
        freopen(taskname ".out", "w", stdout);
    }
    int tt = 1;
    //cin >> tt;
    while (tt--){
        Init();
    }
    if (fopen("timeout.txt", "r")){
        ofstream timeout("timeout.txt");
        cerr << "Time elapsed: " << signed(double(clock()) / CLOCKS_PER_SEC * 1000) << "ms\n";
        timeout << signed(double(clock()) / CLOCKS_PER_SEC * 1000);
        timeout.close();
    }
}

Compilation message

dostavljac.cpp: In function 'int main()':
dostavljac.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen(taskname ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dostavljac.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         freopen(taskname ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 65 ms 1816 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 2388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 109 ms 3428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 209 ms 4196 KB Output isn't correct
2 Halted 0 ms 0 KB -