# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
503046 | 2022-01-07T04:17:32 Z | ismoilov | Biochips (IZhO12_biochips) | C++14 | 268 ms | 402372 KB |
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define all(x) (x).begin(), (x).end() #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++) #define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++) #define fm(a,i,c) for(int (a) = (i); (a) > (c); (a)--) #define fmm(a,i,c) for(int (a) = (i); (a) >= (c); (a)--) const int maxx = 2e5+5; int a[maxx], b[maxx]; int d[maxx][505]; vector <int> g[maxx]; int n, m, r, cnt = 0; void dfs(int v){ b[v] = cnt; for(auto it : g[v]) dfs(it); fpp(i,1,m) d[cnt+1][i] = max(d[cnt][i], d[b[v]][i - 1] + a[v]); cnt ++; } void S() { cin >> n >> m; fpp(i,1,n){ int x; cin >> x >> a[i]; if(x == 0) r = i; else g[x].push_back(i); } fpp(i,1,m) d[0][i] = -maxx; dfs(r); cout << d[n][m]; } int main() { IOS; S(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4940 KB | Output is correct |
2 | Correct | 3 ms | 5020 KB | Output is correct |
3 | Correct | 2 ms | 5196 KB | Output is correct |
4 | Correct | 12 ms | 22988 KB | Output is correct |
5 | Correct | 13 ms | 25000 KB | Output is correct |
6 | Correct | 13 ms | 25036 KB | Output is correct |
7 | Correct | 215 ms | 300180 KB | Output is correct |
8 | Correct | 179 ms | 300208 KB | Output is correct |
9 | Correct | 215 ms | 364572 KB | Output is correct |
10 | Correct | 268 ms | 402372 KB | Output is correct |