| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 1112221 | Kirill22 | Biochips (IZhO12_biochips) | C++17 | 447 ms | 405576 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    vector<int> a(n);
    int rt;
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p >> a[i];
        p--;
        if (p == -1) {
            rt = i;
        } else {
            g[p].push_back(i);
        }
    }
    vector<int> tin(n), tout(n);
    vector<vector<pair<int, int>>> go(n);
    int T = 0;
    auto dfs = [&] (auto& dfs, int v) -> void {
        tin[v] = T++;
        for (auto u : g[v]) {
            dfs(dfs, u);
        }
        tout[v] = T;
        go[tin[v]].push_back({tout[v], a[v]});
    };
    dfs(dfs, rt);
    vector<vector<int>> dp(n + 1, vector<int> (m + 1, -(int) 1e9));
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (auto [r, x] : go[i]) {
            for (int j = 0; j < m; j++) {
                dp[r][j + 1] = max(dp[r][j + 1], dp[i][j] + x);
            }
        }
        for (int j = 0; j <= m; j++) {
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
        }
    }
    cout << dp.back().back();
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
