# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
516782 | 2022-01-22T06:14:05 Z | Be_dos | 바이오칩 (IZhO12_biochips) | C++17 | 1 ms | 204 KB |
#include <iostream> #include <cmath> #include <cctype> #include <vector> #include <algorithm> #include <set> #include <map> #include <deque> #include <stack> #include <unordered_set> #include <sstream> #include <cstring> #include <iomanip> #include <queue> #include <unordered_map> #include <random> #include <cfloat> #include <chrono> #include <bitset> #include <complex> #include <immintrin.h> #include <cassert> int32_t m; void dfs(int32_t v, std::vector<int32_t>* tree, int32_t** dp, int32_t* arr) { for(int32_t i = 0; i < tree[v].size(); i++) dfs(tree[v][i], tree, dp, arr); dp[v] = new int32_t[m + 1]; dp[v][0] = 0; for(int32_t i = 1; i <= m; i++) dp[v][i] = -1'000'000'000; int32_t* tmp = new int32_t[m + 1]; for(int32_t i = 0; i < tree[v].size(); i++) { for(int32_t j = 0; j <= m; j++) { tmp[j] = -1'000'000'000; for(int32_t k = 0; k <= j; k++) tmp[j] = std::max(tmp[j], dp[v][k] + dp[tree[v][i]][j - k]); } int32_t* tmp2 = dp[v]; dp[v] = tmp; tmp = tmp2; } dp[v][1] = std::max(dp[v][1], arr[v]); } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int32_t n; std::cin >> n >> m; int32_t* arr = new int32_t[n]; std::vector<int32_t>* tree = new std::vector<int32_t>[n]; int32_t root = -1; for(int32_t i = 0; i < n - 1; i++) { int32_t parent; std::cin >> parent >> arr[i]; parent--; if(parent == -1) root = i; else tree[parent].push_back(i); } int32_t** dp = new int32_t*[n]; dfs(root, tree, dp, arr); std::cout << dp[root][m]; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 204 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |