답안 #334673

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
334673 2020-12-09T18:15:08 Z iulia13 바이오칩 (IZhO12_biochips) C++14
0 / 100
1321 ms 524292 KB
#include <iostream>
#include <deque>
#include <vector>
using namespace std;
int dp[505][400005];
vector <int> g[200005];
int v[200005];
int in[200005];
int out[200005];
int ord[400005];
int timp = 0;
void dfs(int nod)
{
  	timp++;
    ord[timp] = nod;
    for (int i = 0; i < g[nod].size(); i++)
    {
        int x = g[nod][i];
        dfs(x);
    }
    out[nod] = ++timp;
}
int main()
{
    int n, m, i, j, r, k, l, x;
    cin >> n >> m;
    for (i = 1; i <= n; i++)
    {
        cin >> x >> v[i];
        if (x)
            g[x].push_back(i);
        else
            r = i;
    }
    dfs(r);
    for (j = 0; j <= m; j++)
        for (i = 1; i <= timp; i++)
            dp[j][i] = -2e9;
    dp[0][1] = 0;
    for (j = 0; j <= m; j++)
        for (i = 1; i <= timp; i++)
        {
            int last = out[ord[i]];
            dp[j][i + 1] = max(dp[j][i + 1], dp[j][i]);
            if (j < m)
                dp[j + 1][last] = max(dp[j + 1][last], dp[j][i] + v[ord[i]]);
        }
    cout << dp[m][timp];
    return 0;
}

Compilation message

biochips.cpp: In function 'void dfs(int)':
biochips.cpp:16:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for (int i = 0; i < g[nod].size(); i++)
      |                     ~~^~~~~~~~~~~~~~~
biochips.cpp: In function 'int main()':
biochips.cpp:25:24: warning: unused variable 'k' [-Wunused-variable]
   25 |     int n, m, i, j, r, k, l, x;
      |                        ^
biochips.cpp:25:27: warning: unused variable 'l' [-Wunused-variable]
   25 |     int n, m, i, j, r, k, l, x;
      |                           ^
biochips.cpp:35:8: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   35 |     dfs(r);
      |     ~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5120 KB Output is correct
3 Correct 4 ms 5228 KB Output is correct
4 Correct 21 ms 10092 KB Output is correct
5 Correct 26 ms 11884 KB Output is correct
6 Correct 31 ms 13932 KB Output is correct
7 Correct 1314 ms 359020 KB Output is correct
8 Correct 1321 ms 359024 KB Output is correct
9 Runtime error 388 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Halted 0 ms 0 KB -