# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
49899 | mra2322001 | 바이오칩 (IZhO12_biochips) | C++14 | 2 ms | 256 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define f0(i, n) for(int i=(0); i<n; i++)
#define f1(i, n) for(int i=(1); i<=n; i++)
using namespace std;
typedef long long ll;
const int N = 200002;
const int M = 502;
int f[N][M], n, m, cost[N], d[N][M];
vector <vector <int> > a;
void dfs(int u){
for(auto v:a[u]){
dfs(v);
f1(j, m) d[u][j] = f[u][j];
f1(j, m){
for(int k = 1; k < j; k++){
d[u][j] = max(d[u][j], f[u][j - k] + f[v][k]);
}
}
f1(j, m) d[u][j] = max(f[u][j], max(d[u][j], f[v][j]));
f1(j, m) f[u][j] = d[u][j];
}
f[u][1] = max(f[u][1], cost[u]);
}
main(){
ios_base::sync_with_stdio(0);
cin >> n >> m;
a.resize(n + 1);
int x = -1;
memset(f, -(0x3f3f3f), sizeof(f));
f1(i, n){
int p, c;
cin >> p >> cost[i];
if(p==0){
x = i;
}
else{
a[p].push_back(i);
}
}
dfs(x);
cout << f[x][m];
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |