Submission #1026611

# Submission time Handle Problem Language Result Execution time Memory
1026611 2024-07-18T08:39:39 Z 12345678 Chase (CEOI17_chase) C++17
40 / 100
4000 ms 94724 KB
#include <bits/stdc++.h>

using namespace std;

const int nx=1e5+5, kx=105;

#define ll long long

ll n, k, b[nx], u, v, sm[nx], dp[nx][kx], res;
vector<ll> d[nx];

void dfs(int u, int p)
{
    sm[u]=0;
    for (auto v:d[u]) if (v!=p) sm[u]+=b[v];
    for (int i=1; i<=k; i++) dp[u][i]=max(dp[p][i], dp[p][i-1]+sm[u]), res=max(res, dp[u][i]); //cout<<"debug "<<u<<' '<<i<<' '<<dp[u][i]<<'\n';
    for (auto v:d[u]) if (v!=p) dfs(v, u);
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>k;
    for (int i=1; i<=n; i++) cin>>b[i];
    for (int i=1; i<n; i++) cin>>u>>v, d[u].push_back(v), d[v].push_back(u);
    for (int rt=1; rt<=n; rt++)
    {
        for (int i=0; i<=k; i++) for (int j=1; j<=n; j++) dp[j][i]=0;
        //cout<<"root "<<rt<<'\n';
        dfs(rt, 0);
    }
    cout<<res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 189 ms 4824 KB Output is correct
8 Correct 19 ms 4700 KB Output is correct
9 Correct 16 ms 4832 KB Output is correct
10 Correct 212 ms 4700 KB Output is correct
11 Correct 78 ms 4812 KB Output is correct
12 Correct 29 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4034 ms 94724 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 189 ms 4824 KB Output is correct
8 Correct 19 ms 4700 KB Output is correct
9 Correct 16 ms 4832 KB Output is correct
10 Correct 212 ms 4700 KB Output is correct
11 Correct 78 ms 4812 KB Output is correct
12 Correct 29 ms 4700 KB Output is correct
13 Execution timed out 4034 ms 94724 KB Time limit exceeded
14 Halted 0 ms 0 KB -