Submission #140383

# Submission time Handle Problem Language Result Execution time Memory
140383 2019-08-02T16:56:36 Z abacaba Dostavljač (COCI18_dostavljac) C++14
14 / 140
5 ms 1404 KB
#include <bits/stdc++.h>
using namespace std;

#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

const int inf = 1e9;
const int N = 5e2 + 15;
int n, m, a[N], dp[N][N], ans;
vector <int> g[N];

void dfs(int v, int p = -1) {
    for(int to : g[v]) {
        if(to != p) {
            for(int k = m - 1; k >= 0; --k) {
                dp[to][k + 1] = max(dp[to][k + 1], dp[v][k]);
                if(k + 2 <= m)
                    dp[to][k + 2] = max(dp[to][k + 2], dp[v][k] + a[to]);
            }
            dfs(to, v);
            for(int k = m - 1; k >= 0; --k)
                dp[v][k + 1] = max(dp[v][k + 1], dp[to][k]);
        }
    }
}

int main() {
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    for(int i = 1; i < n; ++i) {
        int u, v;
        scanf("%d%d", &u, &v);
        g[u].pb(v);
        g[v].pb(u);
    }
    for(int i = 0; i < N; ++i)
        for(int j = 0; j < N; ++j)
            dp[i][j] = -inf;
    dp[1][0] = 0, dp[1][1] = a[1];
    dfs(1);
    for(int i = 1; i <= n; ++i)
        ans = max(ans, dp[i][m]);
    printf("%d\n", ans);
    return 0;
}

Compilation message

dostavljac.cpp: In function 'int main()':
dostavljac.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
dostavljac.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
dostavljac.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &u, &v);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1400 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1400 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1400 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1400 KB Output isn't correct
2 Halted 0 ms 0 KB -