Submission #1117609

#TimeUsernameProblemLanguageResultExecution timeMemory
1117609vjudge1Paprike (COI18_paprike)C++17
100 / 100
81 ms19208 KiB
#pragma GCC optimize ("O3") #include<bits/stdc++.h> #define ll long long #define ld long double #define vl vector<ll> #define vi vector<int> #define all(v) v.begin(), v.end() #define pb push_back #define iospeed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; const ll sz = 1e5+5; vl g[sz]; ll vis[sz], val[sz], subtree[sz], res = 0, n, m; void dfs(ll node) { vis[node] = 1; subtree[node] = val[node]; vl v; for(auto u : g[node]) { if(vis[u]) continue; dfs(u); v.pb(subtree[u]); } sort(all(v)); for(auto u : v) { if(subtree[node] + u <= m) subtree[node] += u; else res++; } } int main() { int i, j, x, y; cin >> n >> m; for(i = 1; i <= n; i++) cin >> val[i]; for(i = 1; i <= n - 1; i++) { cin >> x >> y; g[x].pb(y); g[y].pb(x); } dfs(1); cout << res << "\n"; }

Compilation message (stderr)

paprike.cpp: In function 'int main()':
paprike.cpp:37:12: warning: unused variable 'j' [-Wunused-variable]
   37 |     int i, j, x, y;
      |            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...