Submission #1236059

#TimeUsernameProblemLanguageResultExecution timeMemory
1236059badge881Magic Tree (CEOI19_magictree)C++20
22 / 100
68 ms49476 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ll n, m, k; scanf("%lld%lld%lld", &n, &m, &k); vector<ll> g[n + 5]; ll p[n + 5]; for (ll i = 2; i <= n; i++) { scanf("%lld", &p[i]); g[p[i]].push_back(i); } ll u[m], d[m], w[m]; vector<ll> day(n + 5, 0), pt(n + 5, 0); for (ll i = 0; i < m; i++) { scanf("%lld%lld%lld", &u[i], &d[i], &w[i]); day[u[i]] = d[i]; pt[u[i]] = w[i]; } if (k <= 20) { ll dp[n + 5][k + 5], pre[n + 5][k + 5]; memset(dp, 0, sizeof (dp)); memset(pre, 0, sizeof (pre)); for (ll i = n; i >= 1; i--) { for (ll j = 1; j <= k; j++) { for (ll x : g[i]) { dp[i][j] += pre[x][j]; } if (day[i] == j) { dp[i][j] += pt[i]; } } for (ll j = 1; j <= k; j++) pre[i][j] = max(dp[i][j], pre[i][j - 1]); } printf("%d", pre[1][k]); } }

Compilation message (stderr)

magictree.cpp: In function 'int main()':
magictree.cpp:47:18: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   47 |         printf("%d", pre[1][k]);
      |                 ~^   ~~~~~~~~~
      |                  |           |
      |                  int         long long int
      |                 %lld
magictree.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%lld%lld%lld", &n, &m, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
magictree.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         scanf("%lld", &p[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
magictree.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         scanf("%lld%lld%lld", &u[i], &d[i], &w[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...