Submission #1095080

#TimeUsernameProblemLanguageResultExecution timeMemory
1095080SunbaeBiochips (IZhO12_biochips)C++17
100 / 100
355 ms13916 KiB
#include <bits/stdc++.h> #define z exit(0) typedef long long ll; using namespace std; const int N = 2e5 + 5; vector<int> g[N]; ll a[N]; vector<ll> cur, nxt; int invp[N], jump[N], ti; void dfs(int u){ int pre = ti++; invp[pre] = u; for(int v: g[u]) dfs(v); jump[pre] = ti; } signed main(){ int n, K, rt; scanf("%d %d", &n, &K); for(int v = 0, u; v<n; ++v){ scanf("%d %lld", &u, a+v); if(--u >= 0) g[u].push_back(v); else rt = v; } dfs(rt); cur.resize(n+1); nxt.resize(n+1); fill(cur.begin(), cur.end(), INT_MIN); cur[0] = 0; for(int k = 0; k<K; ++k){ fill(nxt.begin(), nxt.end(), INT_MIN); for(int i = 0; i<n; ++i){ cur[i+1] = max(cur[i+1], cur[i]); nxt[jump[i]] = max(nxt[jump[i]], cur[i] + a[invp[i]]); } cur = nxt; } printf("%lld", *max_element(cur.begin(), cur.end())); }

Compilation message (stderr)

biochips.cpp: In function 'int main()':
biochips.cpp:17:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     int n, K, rt; scanf("%d %d", &n, &K);
      |                   ~~~~~^~~~~~~~~~~~~~~~~
biochips.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         scanf("%d %lld", &u, a+v);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~
biochips.cpp:23:8: warning: 'rt' may be used uninitialized in this function [-Wmaybe-uninitialized]
   23 |     dfs(rt);
      |     ~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...