Submission #1034848

# Submission time Handle Problem Language Result Execution time Memory
1034848 2024-07-25T19:59:01 Z MarwenElarbi Chase (CEOI17_chase) C++17
0 / 100
1 ms 600 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define ll long long
#define pb push_back
#define ii pair<int,int>
template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int nax=1e3+5;
const int MOD=1e9+9;
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll INF = 1e18;
int tab[nax];
vector<int> adj[nax];
long long dp[nax];
int n,k;
long long dfs(int x,int p,int cur){
    if(cur==k) return 0;
    for(auto u:adj[x]){
        if(u==p) continue;
        dp[x]+=tab[u];
    }
    long long cnt=0;
    for(auto u:adj[x]){
        if(u==p) continue;
        cnt=max(cnt,dfs(u,x,cur+1));
    }

    return dp[x]+=cnt;
}
int main()
{
    optimise;
    cin>>n>>k;
    for (int i = 0; i < n; ++i)
    {
        cin>>tab[i];
    }
    for (int i = 0; i < n-1; ++i)
    {
        int x,y;
        cin>>x>>y;
        x--;y--;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    long long ans=0;
    for (int i = 0; i < n; ++i)
    {
        memset(dp,0,sizeof dp);
        ans=max(ans,dfs(i,-1,0));
    }
    cout <<ans<<endl;
}

        
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -