Submission #67017

# Submission time Handle Problem Language Result Execution time Memory
67017 2018-08-13T08:21:27 Z MANcity Chase (CEOI17_chase) C++14
0 / 100
57 ms 3824 KB
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<cstring>
#include<vector>
using namespace std;
#define for1(i,n) for(int i=1;i<=(int)n;i++)
#define for0(i,n) for(int i=0;i<=(int)n;i++)
#define forn(i,n) for(int i=n;i>=1;i--)
#define fo(i,x,y) for(int i=x;i<=(int)y;i++)
#define fr(i,x,y) for(int i=x;i>=(int)y;i--)
#define pb push_back
#define mp make_pair
#define LL long long
const LL Mod=1000*1000*1000+7;
int n,k;
LL P[100002];
LL gum[100002];
vector<vector<int> > g(10002);
void dfs(int v,int p)
{
    for0(i,g[v].size()-1)
    {
        int to=g[v][i];
        if(to!=p)
        {
            dfs(to,v);
            gum[v]+=P[to];
        }
    }
}
LL dp[100002][102];
LL ANS[10002];
void solve(int v,int p)
{
    if(v!=1)
    {
        dp[v][0]=ANS[p];
        ANS[v]=ANS[p];
        for1(i,k)
        {
            dp[v][i]=dp[p][i-1]+gum[v];
            ANS[v]=max(ANS[v],dp[v][i]);
        }
    }
    for0(i,g[v].size()-1)
    {
        int to=g[v][i];
        if(to!=p)
            solve(to,v);
    }
}
int main()
{
    cin>>n>>k;
    for1(i,n)
        cin>>P[i];
    for1(i,n-1)
    {
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(1,-1);
    dp[1][1]=gum[1];
    ANS[1]=gum[1];
    solve(1,-1);
    LL ma=0;
    for1(i,n)
        ma=max(ma,ANS[i]);
    cout<<ma<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 57 ms 3824 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -