# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
146744 | 2019-08-25T19:59:11 Z | abacaba | 바이오칩 (IZhO12_biochips) | C++14 | 2000 ms | 25048 KB |
// https://github.com/tmwilliamlin168/CompetitiveProgramming/blob/master/IZhO/14-Shymbulak.cpp #include <iostream> #include <string> #include <cstring> #include <vector> #include <map> #include <set> #include <algorithm> #include <math.h> #include <cstdio> #include <stdio.h> #include <queue> #include <deque> 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 = 2e5 + 1; int n, m, a[N], root; vector <int> g[N]; map <int, int> dp[N]; void dfs(int v) { dp[v][0] = 0; for(int to : g[v]) { dfs(to); vector <pii> temp = {}; for(auto it : dp[v]) for(auto ik : dp[to]) if(ik.f + it.f <= m) temp.pb(mp(ik.f + it.f, ik.se + it.se)); for(pii i : temp) dp[v][i.f] = max(dp[v][i.f], i.se); } dp[v][1] = max(a[v], dp[v][1]); } int main() { scanf("%d%d", &n, &m); for(int i = 1; i <= n; ++i) { int x; scanf("%d%d", &x, &a[i]); if(!x) root = i; else g[x].pb(i); } dfs(root); printf("%d\n", dp[root][m]); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 14456 KB | Output is correct |
2 | Correct | 14 ms | 14456 KB | Output is correct |
3 | Correct | 14 ms | 14456 KB | Output is correct |
4 | Correct | 43 ms | 16376 KB | Output is correct |
5 | Correct | 68 ms | 16476 KB | Output is correct |
6 | Correct | 74 ms | 16536 KB | Output is correct |
7 | Execution timed out | 2052 ms | 25048 KB | Time limit exceeded |
8 | Halted | 0 ms | 0 KB | - |