# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
146563 | 2019-08-24T12:16:34 Z | abacaba | Dostavljač (COCI18_dostavljac) | C++14 | 182 ms | 2424 KB |
#include <iostream> #include <string> #include <queue> #include <cstring> #include <vector> #include <map> #include <algorithm> #include <math.h> #include <utility> #include <set> #include <time.h> #include <list> #include <typeinfo> #include <cstdio> #include <numeric> #include <stack> #include <stdio.h> using namespace std; #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define mp make_pair #define f first #define se second #define pb push_back #define ppb pop_back #define ll long long #define ull unsigned long long #define cntbit(x) __builtin_popcount(x) #define endl '\n' #define uset unordered_set #define umap unordered_map #define pii pair<int, int> #define ld long double #define pll pair<long long, long long> const int inf = 2e9; const int N = 5e2 + 15; int n, m, a[N], dp[2][N][N]; vector <int> g[N]; void dfs(int v, int p = -1) { for(int to : g[v]) if(to != p) { dfs(to, v); for(int i = m; i; --i) for(int j = 0; i - j - 2 >= 0; ++j) { for(int k = 0; k < 2; ++k) dp[0][v][i] = max(dp[0][v][i], dp[k][to][j] + dp[1][v][i - j - 1]); dp[0][v][i] = max(dp[0][v][i], dp[1][v][j] + dp[0][to][i - j - 2]); dp[1][v][i] = max(dp[1][v][i], dp[1][v][j] + dp[1][to][i - j - 2]); } } } int main() { scanf("%d%d", &n, &m); for(int i = 1; i <= n; ++i) scanf("%d", &a[i]); for(int i = 1; i < n; ++i) { int u, v; scanf("%d%d", &u, &v); g[u].push_back(v); g[v].push_back(u); } for(int i = 0; i < 2; ++i) for(int j = 1; j <= n; ++j) for(int k = 1; k <= m; ++k) dp[i][j][k] = a[j]; dfs(1); printf("%d\n", max(dp[0][1][m], dp[1][1][m])); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 504 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 504 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 504 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 632 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 760 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 888 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 50 ms | 1144 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 20 ms | 1656 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 96 ms | 2016 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 182 ms | 2424 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |