Submission #334679

#TimeUsernameProblemLanguageResultExecution timeMemory
334679iulia13Biochips (IZhO12_biochips)C++14
100 / 100
917 ms390652 KiB
#include <iostream> #include <deque> #include <vector> using namespace std; int dp[505][200005]; vector <int> g[200005]; int v[200005]; int in[200005]; int ord[400005]; int out[400005]; int eul[400005]; int timp = 0; void dfs(int nod) { timp++; in[nod] = timp; ord[timp] = nod; dp[1][timp] = v[nod]; for (int i = 0; i < g[nod].size(); i++) { int x = g[nod][i]; dfs(x); } out[in[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); int ans = 0; for (j = 1; j <= m; j++) for (i = timp; i; i--) { dp[j][i] = max(dp[j][i], dp[j][i + 1]); int last = out[i] + 1; if (last <= timp) dp[j][i] = max(dp[j][i], dp[j - 1][last] + v[ord[i]]); if (j == m) ans = max(ans, dp[m][i]); } cout << ans; return 0; }

Compilation message (stderr)

biochips.cpp: In function 'void dfs(int)':
biochips.cpp:19:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (int i = 0; i < g[nod].size(); i++)
      |                     ~~^~~~~~~~~~~~~~~
biochips.cpp: In function 'int main()':
biochips.cpp:28:24: warning: unused variable 'k' [-Wunused-variable]
   28 |     int n, m, i, j, r, k, l, x;
      |                        ^
biochips.cpp:28:27: warning: unused variable 'l' [-Wunused-variable]
   28 |     int n, m, i, j, r, k, l, x;
      |                           ^
biochips.cpp:38:8: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   38 |     dfs(r);
      |     ~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...