Submission #1026150

# Submission time Handle Problem Language Result Execution time Memory
1026150 2024-07-17T16:00:14 Z ShaShi Chase (CEOI17_chase) C++17
30 / 100
113 ms 128872 KB
#include <bits/stdc++.h>
 
#define int long long

// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
 
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define kill(x) cout << x << "\n", exit(0)
#define pii pair<int, int>
#define endl "\n"


 
 
using namespace std;
typedef long long ll;
typedef long double ld;
 

const int MAXN = (int)1e6 + 7;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const int SQ = 107;



int n, m, t, k, tmp, tmp2, tmp3, tmp4, flag, u, v, w;
int arr[MAXN], h[MAXN], sum[MAXN], dp[MAXN][SQ], ans, ps[2][MAXN], pd[MAXN];
vector<int> adj[MAXN], vec[MAXN];




void DFSsz(int v, int p=-1) {
    int sum = 0;

    for (int u:adj[v]) {
        if (u == p) continue;

        DFSsz(u, v);

        sum += arr[u]; vec[v].pb(u);
    }

    for (int j=1; j<=k; j++) {
        for (int u:vec[v]) {
            dp[v][j] = max({dp[v][j], dp[u][j], dp[u][j-1]+sum});
        }
    }

    // ps[0][0] = ps[1][vec[v].size()+1] = {-1, 0};
    // for (int i=1; i<=vec[v].size(); i++) ps[0][i] = merge(ps[0][i-1], {dp[vec[v][i-1]].F+1, dp[vec[v][i-1]].S});
    // for (int i=vec[v].size(); i>=1; i--) ps[1][i] = merge(ps[1][i+1], {dp[vec[v][i-1]].F+1, dp[vec[v][i-1]].S});
    // for (int i=1; i<=vec[v].size(); i++) pd[vec[v][i-1]] = merge(ps[0][i-1], ps[1][i+1]);
}



// void Walk(int v, int p=-1, pii mul={0, 1}) {
//     ans = merge(ans, merge(dp[v], mul));

//     // cout << "! " << v << " " << merge(dp[v], mul).F << " " << merge(dp[v], mul).S << endl;

//     for (int u:adj[v]) {
//         if (u == p) continue;

//         Walk(u, v, {merge(mul, pd[u]).F+1, merge(mul, pd[u]).S});
//     }
// }


int32_t main() {
    #ifdef LOCAL
    freopen("inp.in", "r", stdin);
    freopen("res.out", "w", stdout);
    #else
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #endif


    cin >> n >> k;

    for (int i=1; i<=n; i++) cin >> arr[i];

    for (int i=1; i<n; i++) {
        cin >> u >> v;

        adj[u].pb(v); adj[v].pb(u);
    }

    DFSsz(1);

    // for (int i=1; i<=n; i++) {
    //     for (int j=0; j<=k; j++) {
    //         cout << "! " << i << " " << j << " : " << dp[i][j] << endl;
    //     }
    // }

    cout << (*max_element(dp[1], dp[1]+k+1)) << endl;


    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 49756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 49756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 82 ms 102044 KB Output is correct
2 Correct 81 ms 104020 KB Output is correct
3 Correct 68 ms 57288 KB Output is correct
4 Correct 79 ms 126548 KB Output is correct
5 Correct 113 ms 128872 KB Output is correct
6 Correct 108 ms 128852 KB Output is correct
7 Correct 107 ms 128596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 49756 KB Output isn't correct
2 Halted 0 ms 0 KB -