Submission #748287

#TimeUsernameProblemLanguageResultExecution timeMemory
748287Username4132Paprike (COI18_paprike)C++14
100 / 100
62 ms21052 KiB
#include<iostream> #include<vector> #include<algorithm> using namespace std; #define forn(i, n) for(int i=0; i<(int)n; ++i) #define forsn(i, s, n) for(int i=s; i<(int)n; ++i) #define dforn(i, n) for(int i=n-1; i>=0; --i) #define dforsn(i, s, n) for(int i=n-1; i>=s; --i) #define PB push_back const int MAXN=100010; int n, k, ans, arr[MAXN], par[MAXN], dep[MAXN], order[MAXN]; vector<int> g[MAXN], lis[MAXN]; void dfs(int v, int p){ par[v]=p; for(int to:g[v]) if(to!=p) { dep[to]=dep[v]+1; dfs(to, v); } } int main(){ scanf("%d %d", &n, &k); forn(i, n) scanf("%d", &arr[i]), order[i]=i; forn(i, n-1){ int a, b; scanf("%d %d", &a, &b); --a, --b; g[a].PB(b), g[b].PB(a); } dfs(0, 0); forn(i, n) lis[dep[i]].PB(i); dforsn(d, 1, n){ sort(lis[d].begin(), lis[d].end(), [](int a, int b){ return arr[a]<arr[b]; }); for(int ind:lis[d]){ if(arr[ind]+arr[par[ind]]<=k) arr[par[ind]]+=arr[ind]; else ans++; } } printf("%d\n", ans); }

Compilation message (stderr)

paprike.cpp: In function 'int main()':
paprike.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
paprike.cpp:25:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     forn(i, n) scanf("%d", &arr[i]), order[i]=i;
      |                ~~~~~^~~~~~~~~~~~~~~
paprike.cpp:27:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         int a, b; scanf("%d %d", &a, &b); --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...