Submission #121561

#TimeUsernameProblemLanguageResultExecution timeMemory
121561sofhiasouzaChase (CEOI17_chase)C++14
30 / 100
1771 ms97440 KiB
#include <bits/stdc++.h> #define pb push_back using namespace std; typedef long long int ll; const int maxn = 1e5+10; int n, v, vet[maxn]; ll dp[maxn][110]; vector < int > grafo[maxn]; ll dfs(int u, int val, int pai) { if(val == 0) return 0; if(dp[u][val]) return dp[u][val]; ll resp1 = 0, resp2 = 0, cont = 0; for(int i = 0 ; i < grafo[u].size() ; i++) { int v = grafo[u][i]; if(v == pai) continue; cont += vet[v]; resp1 = max(resp1, dfs(v, val-1, u)); resp2 = max(resp2, dfs(v, val, u)); } resp1 += cont; return dp[u][val] = max(resp1, resp2); } int main() { cin >> n >> v; for(int i = 1 ; i <= n ; i++) cin >> vet[i]; for(int i = 0 ; i < n-1 ; i++) { int a, b; cin >> a >> b; grafo[a].pb(b); grafo[b].pb(a); } ll resp = dfs(1, v, 0); if(n <= 10) { for(int i = 2 ; i <= n ; i++) resp = max(resp, dfs(i, v, 0)); } cout << resp << endl; }

Compilation message (stderr)

chase.cpp: In function 'll dfs(int, int, int)':
chase.cpp:19:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0 ; i < grafo[u].size() ; i++)
                  ~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...