Submission #985628

# Submission time Handle Problem Language Result Execution time Memory
985628 2024-05-18T10:43:44 Z Alebn Chase (CEOI17_chase) C++14
50 / 100
607 ms 178684 KB
#include <bits/stdc++.h>
#define int long long

using namespace std;

int n, k, x, y, ia, ib, va, vb, ic, id;
vector<int> a, b;
vector<vector<int>> graph, dp, dpe;

void dfs(int i, int p) {
    for(auto j : graph[i]) {
        if(j != p) dfs(j, i);
    }
    //
    y = 0;
    for(int j = 0; j <= k; j++) {
        ia = -1, ib = -1, va = 0, vb = 0, ic = -1, id = -1;
        for(auto z : graph[i]) {
            if(z != p) {
                dp[i][j] = max(dp[i][j], max(dp[z][j], (j == k || dp[z][j + 1] == LLONG_MIN ? LLONG_MIN : dp[z][j + 1] + b[i] - (p == -1 ? 0 : a[p]))));
                dpe[i][j] = max(dpe[i][j], max(dpe[z][j], (j == k || dpe[z][j + 1] == LLONG_MIN ? LLONG_MIN : dpe[z][j + 1] + b[i] - (j + 1 == k ? 0 : a[z]))));
                //
                y = max(y, max(dp[i][j], (p == -1 || j == k ? LLONG_MIN : dp[z][j + 1] + b[i])));
                y = max(y, dpe[i][j]);
                //
                int temp = max(dpe[z][j], (j == k || dpe[z][j + 1] == LLONG_MIN ? LLONG_MIN : dpe[z][j + 1] + b[i] - a[z]));
                if(ia == -1 || temp > va) {
                    ib = ia, vb = va, ia = z, va = temp;
                } else if(ib == -1 || temp > vb) {
                    ib = z, vb = temp;
                }
                if(i == 6 && vb == 21) cout << dpe[i][j] << " " <<j << " " << z << "\n";
                //
                if(ic == -1 || dp[z][k - j] > dp[ic][k - j]) {
                    id = ic, ic = z;
                } else if(id == -1 || dp[z][k - j] > dp[id][k - j]) {
                    id = z;
                }
            }
        }
        if(ia != ic && ia != -1 && ic != -1) y = max(y, va + dp[ic][k - j]); 
        if(y == 37) cout << "mjau\n";
        if(ib != ic && ib != -1 && ic != -1) y = max(y, vb + dp[ic][k - j]);
        if(y == 37) cout << "mjau2\n";
        if(ia != id && ia != -1 && id != -1) y = max(y, va + dp[id][k - j]);
    if(y == 37) cout << i << " " << j << " " << ia << " " << va << " " << ib << " " << vb << " " << ic << " " << id << "be\n";
    }
    x = max(x, y);
}

signed main() {
    cin >> n >> k;
    a = vector<int>(n), b = vector<int>(n), graph = vector<vector<int>>(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n - 1; i++) {
        cin >> x >> y;
        x--, y--;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < graph[i].size(); j++) b[i] += a[graph[i][j]];
    }
    //
    dp = vector<vector<int>>(n, vector<int>(k + 1)), dpe = vector<vector<int>>(n, vector<int>(k + 1));
    x = 0;
    dfs(0, -1);
    //
    cout << x << "\n";
}

Compilation message

chase.cpp: In function 'int main()':
chase.cpp:62:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         for(int j = 0; j < graph[i].size(); j++) b[i] += a[graph[i][j]];
      |                        ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 3 ms 2140 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Incorrect 1 ms 604 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 363 ms 178684 KB Output is correct
2 Correct 338 ms 178512 KB Output is correct
3 Correct 607 ms 172664 KB Output is correct
4 Correct 111 ms 18948 KB Output is correct
5 Correct 355 ms 172684 KB Output is correct
6 Correct 356 ms 172332 KB Output is correct
7 Correct 386 ms 172468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 3 ms 2140 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Incorrect 1 ms 604 KB Output isn't correct
10 Halted 0 ms 0 KB -