Submission #163098

#TimeUsernameProblemLanguageResultExecution timeMemory
163098arnold518Chase (CEOI17_chase)C++14
30 / 100
303 ms98168 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e5; const int MAXK = 100; int N, K; ll P[MAXN+10], S[MAXN+10], dp1[MAXN+10][MAXK+10], dp2[MAXN+10][MAXK+10]; vector<int> adj[MAXN+10]; void dfs1(int now, int bef) { int i, j; S[now]+=P[bef]; for(int nxt : adj[now]) { if(nxt==bef) continue; dfs1(nxt, now); S[now]+=P[nxt]; } for(i=1; i<=K; i++) { ll val=0; for(int nxt : adj[now]) { if(nxt==bef) continue; val=max(val, dp1[nxt][i-1]); dp1[now][i]=max(dp1[now][i], dp1[nxt][i]); } dp1[now][i]=max(dp1[now][i], S[now]-P[bef]+val); } } void dfs2(int now, int bef) { int i, j; for(int nxt : adj[now]) { if(nxt==bef) continue; } } int main() { int i, j; scanf("%d%d", &N, &K); for(i=1; i<=N; i++) scanf("%lld", &P[i]); for(i=1; i<N; i++) { int u, v; scanf("%d%d", &u, &v); adj[u].push_back(v); adj[v].push_back(u); } dfs1(1, 0); printf("%lld", dp1[1][K]); }

Compilation message (stderr)

chase.cpp: In function 'void dfs1(int, int)':
chase.cpp:17:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
chase.cpp: In function 'void dfs2(int, int)':
chase.cpp:41:9: warning: unused variable 'i' [-Wunused-variable]
     int i, j;
         ^
chase.cpp:41:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
chase.cpp: In function 'int main()':
chase.cpp:51:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
chase.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &N, &K);
     ~~~~~^~~~~~~~~~~~~~~~
chase.cpp:54:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1; i<=N; i++) scanf("%lld", &P[i]);
                         ~~~~~^~~~~~~~~~~~~~~
chase.cpp:58:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &u, &v);
         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...