(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #222894

#TimeUsernameProblemLanguageResultExecution timeMemory
222894kingfran1907Paprike (COI18_paprike)C++14
100 / 100
95 ms21240 KiB
#include <bits/stdc++.h> using namespace std; typedef long long llint; const int maxn = 1e5+10; int n; llint k; llint h[maxn]; vector< int > graph[maxn]; pair<llint, llint> dfs(int x, int parr) { llint sol = 0; llint wh = h[x]; vector< int > v; for (int i = 0; i < graph[x].size(); i++) { int tren = graph[x][i]; if (tren == parr) continue; pair<llint, llint> ac = dfs(tren, x); sol += ac.first; v.push_back(ac.second); wh += ac.second; } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); int ptr = 0; while (wh > k) { wh -= v[ptr++]; sol++; } return make_pair(sol, wh); } int main() { scanf("%d%lld", &n, &k); for (int i = 1; i <= n; i++) scanf("%lld", h+i); for (int i = 1; i < n; i++) { int a, b; scanf("%d%d", &a, &b); graph[a].push_back(b); graph[b].push_back(a); } printf("%lld\n", dfs(1, -1)); return 0; }

Compilation message (stderr)

paprike.cpp: In function 'std::pair<long long int, long long int> dfs(int, int)':
paprike.cpp:17:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < graph[x].size(); i++) {
                     ~~^~~~~~~~~~~~~~~~~
paprike.cpp: In function 'int main()':
paprike.cpp:51:32: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type 'std::pair<long long int, long long int>' [-Wformat=]
     printf("%lld\n", dfs(1, -1));
                      ~~~~~~~~~~^
paprike.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%lld", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~~~
paprike.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", h+i);
         ~~~~~^~~~~~~~~~~~~
paprike.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...