제출 #239761

#제출 시각아이디문제언어결과실행 시간메모리
239761VEGAnnDostavljač (COCI18_dostavljac)C++14
14 / 140
269 ms2296 KiB
#include <bits/stdc++.h> #define PB push_back #define sz(x) ((int)x.size()) #define i3 array<int,3> using namespace std; typedef long double ld; typedef long long ll; const int N = 510; const int M = 510; const int K = 110; const int T = 2010; const int oo = 2e9; vector<int> g[N]; int n, m, a[N], f[N][M][2], ans = 0; int upd(int &x, int y){ x = max(x, y); } void dfs(int v, int p){ // for (int cur = m - 1; cur >= 0; cur--) // upd(f[v][cur + 1][0], f[v][cur][0] + a[v]); f[v][1][0] = a[v]; for (int u : g[v]){ if (u == p) continue; dfs(u, v); for (int cur = m; cur >= 0; cur--) for (int nw = m; nw >= 0; nw--) { if (cur + nw + 2 <= m) upd(f[v][cur + nw + 2][0], f[v][cur][0] + f[u][nw][0]); if (cur + nw + 1 <= m) upd(f[v][cur + nw + 1][1], f[v][cur][0] + max(f[u][nw][0], f[u][nw][1])); } } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #ifdef _LOCAL freopen("in.txt","r",stdin); #endif // _LOCAL cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 1; i < n; i++){ int x, y; cin >> x >> y; x--; y--; g[x].PB(y); g[y].PB(x); } dfs(0, -1); for (int kl = 0; kl <= m; kl++) { upd(ans, f[0][kl][0]); upd(ans, f[0][kl][1]); } cout << ans; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

dostavljac.cpp: In function 'int upd(int&, int)':
dostavljac.cpp:18:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...