Submission #363906

# Submission time Handle Problem Language Result Execution time Memory
363906 2021-02-07T13:27:02 Z dolphingarlic Chase (CEOI17_chase) C++14
30 / 100
154 ms 76524 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int n, k, p[100001];
vector<int> graph[100001];
ll dp[100001][101];

void dfs1(int node = 1, int parent = 0) {
    ll c_sum = 0;
    for (int i : graph[node]) if (i != parent) c_sum += p[i];
    for (int i : graph[node]) if (i != parent) {
        dfs1(i, node);
        for (int j = 1; j <= k; j++)
            dp[node][j] = max({dp[node][j], dp[i][j], dp[i][j - 1] + c_sum});
    }
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> p[i];
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    dfs1();
    cout << dp[1][k];
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 121 ms 52588 KB Output is correct
2 Correct 119 ms 52584 KB Output is correct
3 Correct 71 ms 8932 KB Output is correct
4 Correct 133 ms 74460 KB Output is correct
5 Correct 154 ms 76524 KB Output is correct
6 Correct 154 ms 76524 KB Output is correct
7 Correct 153 ms 76268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2668 KB Output isn't correct
2 Halted 0 ms 0 KB -