(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 #242650

#TimeUsernameProblemLanguageResultExecution timeMemory
242650vanicPaprike (COI18_paprike)C++14
100 / 100
97 ms17656 KiB
#include <iostream> #include <cstdio> #include <math.h> #include <algorithm> #include <set> #include <stack> #include <vector> using namespace std; const int maxn=1e5+5; int val[maxn]; vector < int > ms[maxn]; int sol; int n, k; int dfs(int x, int prosl){ vector < int > svi; for(int i=0; i<ms[x].size(); i++){ if(ms[x][i]!=prosl){ svi.push_back(dfs(ms[x][i], x)); } } sort(svi.begin(), svi.end()); int poc=val[x]; for(int i=0; i<svi.size(); i++){ if(poc+svi[i]<=k){ poc+=svi[i]; } else{ sol+=svi.size()-i; break; } } return poc; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; for(int i=0; i<n; i++){ cin >> val[i]; } int x, y; for(int i=0; i<n-1; i++){ cin >> x >> y; x--; y--; ms[x].push_back(y); ms[y].push_back(x); } dfs(0, 0); cout << sol << '\n'; return 0; }

Compilation message (stderr)

paprike.cpp: In function 'int dfs(int, int)':
paprike.cpp:20:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<ms[x].size(); i++){
               ~^~~~~~~~~~~~~
paprike.cpp:27:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<svi.size(); 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...