제출 #1117658

#제출 시각아이디문제언어결과실행 시간메모리
1117658raul2008487Paprike (COI18_paprike)C++17
13 / 100
39 ms20816 KiB
#include<bits/stdc++.h> #define ll long long #define pb push_back #define in insert #define fi first #define se second #define vl vector<ll> #define all(v) v.begin(), v.end() #define endl "\n" using namespace std; const int sz = 1e5 + 123; /// mind this const int MAX = 2e6 + 123; const int BS = 61; const ll inf = 1e17; const int mod = 998244353; ll c[sz], s[sz], par[sz], ans, k; vl e[sz]; void init(ll v, ll p){ par[v] = p; for(auto to: e[v]){ if(to != p){ init(to, v); s[v] += s[to]; } } s[v] += c[v]; } ll dfs(ll v, ll p){ if(s[v] <= k){return s[v];} vl children; for(auto to: e[v]){ if(to != p){ s[v] -= s[to]; children.pb(dfs(to, v)); s[v] += s[to]; } } if(s[v] > k){ sort(all(children)); while(s[v] > k){ s[v] -= children.back(); ans ++; } } assert(s[v] <= k); return s[v]; } void solve(){ ll n, i, j, u, v; cin >> n >> k; for(i = 1; i <= n; i++){ cin >> c[i]; } for(i = 1; i < n; i++){ cin >> u >> v; e[u].pb(v); e[v].pb(u); } init(1, 0); dfs(1, 0); cout << ans << endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll t = 1; // cin >> t; while(t--){ solve(); } } /* 1 2 9 0 */

컴파일 시 표준 에러 (stderr) 메시지

paprike.cpp: In function 'void solve()':
paprike.cpp:51:14: warning: unused variable 'j' [-Wunused-variable]
   51 |     ll n, i, j, u, v;
      |              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...