| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 31926 | kazel | 바이오칩 (IZhO12_biochips) | C++14 | 0 ms | 12176 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int val[200001], m;
vector<int> g[200001], dp[200001];
void dfs(int c)
{
    if(g[c].empty())
    {
        dp[c].push_back(val[c]);
        return;
    }
    priority_queue<tuple<int,int,int>> pq;
    for(int e : g[c])
    {
        dfs(e);
        pq.emplace(dp[e][0],e,1);
    }
    int v = 0;
    for(int t=0;t<m;t++)
    {
        if(pq.empty()) break;
        int x,y,z;
        tie(x,y,z) = pq.top();
        pq.pop();
        v += x;
        dp[c].push_back(v);
        if(dp[y].size()<=z) continue;
        x = dp[y][z]-x;
        pq.emplace(x,y,z+1);
    }
    if(dp[c].empty()) dp[c].push_back(val[c]);
    if(dp[c][0] < val[c]) dp[c][0] = val[c];
    for(int e : g[c]) dp[e].clear();
}
int main()
{
    int n, r;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        int p;
        scanf("%d%d",&p,val+i);
        if(!p) r = i;
        else g[p].push_back(i);
    }
    dfs(r);
    printf("%d\n",dp[r][m-1]);
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
