Submission #759355

#TimeUsernameProblemLanguageResultExecution timeMemory
759355HanksburgerPaprike (COI18_paprike)C++17
100 / 100
38 ms19868 KiB
#include <bits/stdc++.h> using namespace std; int a[100005], b[100005], c[100005], n, m; vector<int> adj[100005]; void dfs(int u, int p) { for (int v:adj[u]) if (v!=p) dfs(v, u); vector<int> vec; for (int v:adj[u]) { if (v!=p) { vec.push_back(c[v]); b[u]+=b[v]+1; } } c[u]=a[u]; sort(vec.begin(), vec.end()); for (int i=0; i<vec.size(); i++) { if (c[u]+vec[i]<=m) { b[u]--; c[u]+=vec[i]; } } } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i=1; i<=n; i++) cin >> a[i]; for (int i=1; i<n; i++) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } dfs(1, 0); cout << b[1]; }

Compilation message (stderr)

paprike.cpp: In function 'void dfs(int, int)':
paprike.cpp:21:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for (int i=0; i<vec.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...