답안 #89332

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
89332 2018-12-11T18:17:20 Z stefdasca 바이오칩 (IZhO12_biochips) C++14
0 / 100
6 ms 5084 KB
/*
        IZhO 12-biochips

    This


*/

#include<bits/stdc++.h>
using namespace std;
int n, m, root, val[200002];
vector<int>v[200002];
int dp2[200002][502], sz2[200002];
int qq = 0;
void dfs(int nod)
{
     for(int i = 1; i <= m; ++i)
         dp2[nod][i] = -1;
     sz2[nod] = 1;
     for(int i = 0; i < v[nod].size(); ++i)
     {
         int vecin = v[nod][i];
         dfs(vecin);
         for(int j = m; j >= 0; --j)
         {
             if(dp2[nod][j] != -1)
                for(int k = 0; k + j <= m && k <= sz2[vecin]; ++k)
                {
                    if(dp2[vecin][k] != -1)
                        dp2[nod][j + k] = max(dp2[nod][j + k], dp2[nod][j] + dp2[vecin][k]), sz2[nod] = j + k;
                    if(k == 1)
                        dp2[nod][j + k] = max(dp2[nod][j + k], dp2[nod][j] + val[vecin]), sz2[nod] = j + k;
                }
         }
     }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> m;
    for(int i = 1; i <= n; ++i)
    {
        int parent;
        cin >> parent;
        cin >> val[i];
        if(parent == 0)
            root = i;
        else
            v[parent].push_back(i);
    }
    dfs(root);
    int ans = 0;
    if(m == 1)
        ans = val[root];
    cout << max(ans, dp2[root][m]) << '\n';
    return 0;
}

Compilation message

biochips.cpp: In function 'void dfs(int)':
biochips.cpp:20:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      for(int i = 0; i < v[nod].size(); ++i)
                     ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 5084 KB Output isn't correct
2 Halted 0 ms 0 KB -