Submission #939607

# Submission time Handle Problem Language Result Execution time Memory
939607 2024-03-06T15:03:27 Z vjudge1 Chase (CEOI17_chase) C++17
40 / 100
229 ms 94092 KB
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N=1e5+5;
vector <int> g[N];
int fr_sum[N],x[N];
int dp[N][105];
int n,k;
void dfs(int v,int p){
    for(auto to : g[v]){
        if(to!=p){
            for(int i=1;i<=k;i++)dp[to][i]=max(dp[v][i],dp[v][i-1]+fr_sum[to]-x[v]);
            dfs(to,v);
        }
    }
}
signed main(){
    ios_base::sync_with_stdio();
    cin.tie(0);cout.tie(0);
    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>x[i];
    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        g[u].pb(v);
        g[v].pb(u);
        fr_sum[v]+=x[u];
        fr_sum[u]+=x[v];
    }
    int ans=0;
    if(n<=1000){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                for(int t=0;t<=k;t++){
                    dp[j][t]=0;
                }
            }
            for(int j=1;j<=k;j++){
                dp[i][j]=fr_sum[i];
            }
            dfs(i,0);
            for(int j=1;j<=n;j++){
                for(int t=0;t<=k;t++){
                    ans=max(ans,dp[j][t]);
                }
            }
        }
        cout<<ans<<"\n";
        return 0;
    }
    dfs(1,0);
    for(int j=1;j<=n;j++){
        for(int t=0;t<=k;t++){
            ans=max(ans,dp[j][t]);
        }
    }
    cout<<ans<<"\n";
}
/*
 12 2
 2 3 3 8 1 5 6 7 8 3 5 4
 2 1
 2 7
 3 4
 4 7
 7 6
 5 6
 6 8
 6 9
 7 10
 10 11
 10 12
*/
           
 
           
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6232 KB Output is correct
2 Correct 1 ms 6232 KB Output is correct
3 Correct 1 ms 6236 KB Output is correct
4 Correct 2 ms 6644 KB Output is correct
5 Correct 2 ms 6236 KB Output is correct
6 Correct 1 ms 6236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6232 KB Output is correct
2 Correct 1 ms 6232 KB Output is correct
3 Correct 1 ms 6236 KB Output is correct
4 Correct 2 ms 6644 KB Output is correct
5 Correct 2 ms 6236 KB Output is correct
6 Correct 1 ms 6236 KB Output is correct
7 Correct 217 ms 8536 KB Output is correct
8 Correct 22 ms 8540 KB Output is correct
9 Correct 24 ms 8540 KB Output is correct
10 Correct 229 ms 8592 KB Output is correct
11 Correct 80 ms 8540 KB Output is correct
12 Correct 33 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 147 ms 94092 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6232 KB Output is correct
2 Correct 1 ms 6232 KB Output is correct
3 Correct 1 ms 6236 KB Output is correct
4 Correct 2 ms 6644 KB Output is correct
5 Correct 2 ms 6236 KB Output is correct
6 Correct 1 ms 6236 KB Output is correct
7 Correct 217 ms 8536 KB Output is correct
8 Correct 22 ms 8540 KB Output is correct
9 Correct 24 ms 8540 KB Output is correct
10 Correct 229 ms 8592 KB Output is correct
11 Correct 80 ms 8540 KB Output is correct
12 Correct 33 ms 8540 KB Output is correct
13 Incorrect 147 ms 94092 KB Output isn't correct
14 Halted 0 ms 0 KB -