# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
673382 | smartmonky | 바이오칩 (IZhO12_biochips) | C++14 | 450 ms | 292920 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
using namespace std;
void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
const int N = 200005;
vector <int> g[N];
int coast[N], dp[505][N], sz[N];
int m;
void dfs(int v){
sz[v] = 1;
for(auto to : g[v]){
dfs(to);
for(int i = min(sz[v], m); i >= 0; i--){
for(int j = min(sz[to], m - i); j >= 0; j--){
if(i + j <= m)
dp[i + j][v] = max(dp[i][v] + dp[j][to], dp[i + j][v]);
}
}
sz[v] += sz[to];
}
dp[1][v] = max(dp[1][v], coast[v]);
}
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//fp("game");
int n;
cin >> n >> m;
int ind = -1;
for(int i = 0; i < n; i++){
int a, b;
cin >> a >> b;
coast[i + 1] = b;
if(a == 0){
ind = i + 1;
continue;
}
g[a].pb(i + 1);
}
dfs(ind);
cout << dp[m][ind];
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |