# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
443798 | JovanB | 바이오칩 (IZhO12_biochips) | C++17 | 657 ms | 414940 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int val[200005];
int par[200005];
vector <int> graf[200005];
int tajm;
int in[200005];
int out[200005];
int niz[200005];
int dp[200005][505];
void dfs(int v){
in[v] = ++tajm;
for(auto c : graf[v]) dfs(c);
out[v] = tajm;
}
vector <pair <int, int>> vec[200005];
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n, m;
cin >> n >> m;
vector <int> roots;
for(int i=1; i<=n; i++){
cin >> par[i] >> val[i];
if(par[i]) graf[par[i]].push_back(i);
else roots.push_back(i);
}
for(auto c : roots) dfs(c);
for(int i=1; i<=n; i++){
//cout << in[i] << " " << out[i] << " " << val[i] << endl;
vec[out[i]].push_back({in[i]-1, val[i]});
}
for(int i=0; i<=n; i++){
for(int j=1; j<=m; j++){
dp[i][j] = -1000000000;
}
}
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
dp[i][j] = dp[i-1][j];
for(auto c : vec[i]){
dp[i][j] = max(dp[i][j], dp[c.first][j-1] + c.second);
}
}
}
cout << dp[n][m];
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |