| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 16895 | erdemkiraz | 바이오칩 (IZhO12_biochips) | C++98 | 541 ms | 405132 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); it++)
typedef long long ll;
typedef pair < int, int > ii;
const int inf = 1e9 + 333;
const ll linf = 1e18 + inf;
const int N = 2e5 + 5;
const int M = 500 + 5;
int n, m, tick, root;
int st[N], nd[N], ord[N], a[N], dp[M][N];
vector < int > v[N];
void dfs(int x) {
    st[x] = ++tick;
    foreach(it, v[x]) {
        int u = *it;
        dfs(u);
    }
    nd[x] = tick;
}
bool cmp(int x, int y) {
    return st[x] < st[y];
}
int main() {
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= n; i++) {
        int x;
        scanf("%d %d", &x, a + i);
        if(!x) {
            root = i;
        }
        v[x].push_back(i);
        ord[i] = i;
    }
    dfs(root);
    sort(ord + 1, ord + n + 1, cmp);
    dp[0][n + 1] = -inf;
    for(int i = 1; i <= m; i++) {
        for(int j = n; j >= 1; j--) {
            int x = ord[j];
            dp[i][j] = max(dp[i][j + 1], dp[i - 1][nd[x] + 1] + a[x]);
        }
        dp[i][n + 1] = -inf;
    }
    printf("%d\n", dp[m][1]);
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
