Submission #1236053

#TimeUsernameProblemLanguageResultExecution timeMemory
1236053badge881Magic Tree (CEOI19_magictree)C++20
0 / 100
30 ms9024 KiB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main()
{
    ll n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    vector<ll> g[n + 5];
    ll p[n + 5];
    for (ll i = 2; i <= n; i++)
    {
        scanf("%d", &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("%d%d%d", &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:10:13: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   10 |     scanf("%d%d%d", &n, &m, &k);
      |            ~^       ~~
      |             |       |
      |             int*    long long int*
      |            %lld
magictree.cpp:10:15: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
   10 |     scanf("%d%d%d", &n, &m, &k);
      |              ~^         ~~
      |               |         |
      |               int*      long long int*
      |              %lld
magictree.cpp:10:17: warning: format '%d' expects argument of type 'int*', but argument 4 has type 'long long int*' [-Wformat=]
   10 |     scanf("%d%d%d", &n, &m, &k);
      |                ~^           ~~
      |                 |           |
      |                 int*        long long int*
      |                %lld
magictree.cpp:15:17: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   15 |         scanf("%d", &p[i]);
      |                ~^   ~~~~~
      |                 |   |
      |                 |   long long int*
      |                 int*
      |                %lld
magictree.cpp:22:17: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   22 |         scanf("%d%d%d", &u[i], &d[i], &w[i]);
      |                ~^       ~~~~~
      |                 |       |
      |                 int*    long long int*
      |                %lld
magictree.cpp:22:19: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
   22 |         scanf("%d%d%d", &u[i], &d[i], &w[i]);
      |                  ~^            ~~~~~
      |                   |            |
      |                   int*         long long int*
      |                  %lld
magictree.cpp:22:21: warning: format '%d' expects argument of type 'int*', but argument 4 has type 'long long int*' [-Wformat=]
   22 |         scanf("%d%d%d", &u[i], &d[i], &w[i]);
      |                    ~^                 ~~~~~
      |                     |                 |
      |                     int*              long long int*
      |                    %lld
magictree.cpp:43:18: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   43 |         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("%d%d%d", &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("%d", &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("%d%d%d", &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...