Submission #67028

#TimeUsernameProblemLanguageResultExecution timeMemory
67028MANcityChase (CEOI17_chase)C++14
0 / 100
280 ms92260 KiB
#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(100002); 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) { if(p!=1 || i!=1) 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) { // if(ANS[i]==20) // cout<<i<<endl; ma=max(ma,ANS[i]); } cout<<ma<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...