Submission #930523

# Submission time Handle Problem Language Result Execution time Memory
930523 2024-02-20T05:36:42 Z sleepntsheep Paprike (COI18_paprike) C++17
Compilation error
0 ms 0 KB
#include <stdio.h>
#include <vector>
#include <string>
#define N 100003

int n, K, a[N];
std::basic_string<int> g[N];

int dp[N];
long long b[N];

void dfs(int u, int p)
{
    b[u] += a[u];

    std::vector<long long> bot;

    for (int v : g[u]) if ( v - p )
    {
        dfs(v, u);
        bot.push_back(b[v]);
        dp[u] += dp[v];
        b[u] += b[v];
    }
    std::sort(bot.begin(), bot.end());

    while (b[u] > K)
    {
        b[u] -= bot.back();
        ++dp[u];
        bot.pop_back();
    }
}

int main()
{
    scanf("%d%d", &n, &K);
    for (int i = 1; i <= n; ++i) scanf("%d", a+i);
    for (int u, v, i = 1; i < n; ++i) scanf("%d%d", &u, &v), g[u].push_back(v), g[v].push_back(u);
    dfs(1, 1);
    printf("%d", dp[1]);
    return 0;
}

Compilation message

paprike.cpp: In function 'void dfs(int, int)':
paprike.cpp:25:10: error: 'sort' is not a member of 'std'
   25 |     std::sort(bot.begin(), bot.end());
      |          ^~~~
paprike.cpp: In function 'int main()':
paprike.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     scanf("%d%d", &n, &K);
      |     ~~~~~^~~~~~~~~~~~~~~~
paprike.cpp:38:39: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     for (int i = 1; i <= n; ++i) scanf("%d", a+i);
      |                                  ~~~~~^~~~~~~~~~~
paprike.cpp:39:44: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     for (int u, v, i = 1; i < n; ++i) scanf("%d%d", &u, &v), g[u].push_back(v), g[v].push_back(u);
      |                                       ~~~~~^~~~~~~~~~~~~~~~