(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.

제출 #68225

#제출 시각아이디문제언어결과실행 시간메모리
68225NordwayPaprike (COI18_paprike)C++14
100 / 100
225 ms28872 KiB
#include<bits/stdc++.h> #define x first #define y second #define pb push_back #define mp make_pair #define in insert #define up_b upper_bound #define low_b lower_bound #define sz(x) (int)x.size() #define all(v) v.begin(),v.end() using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<int,ll> pil; typedef pair<ll,int> pli; typedef pair<ll,ll> pll; const ll INF = 1e18; const int inf = INT_MAX; const ll mod = 1e9 + 7; const int dx[4] = {0, 0, 1, -1}; const int dy[4] = {1, -1, 0, 0}; const int N = 1e5 + 5; const int A = 26; ll n, k, ans, a[N], d[N]; vector < int > g[N]; void dfs(int v, int p){ vector < int > val; d[v] = a[v]; for(int i = 0; i < sz(g[v]); i++){ int to = g[v][i]; if(to != p){ dfs(to, v); d[v] += d[to]; val.pb(d[to]); } } sort(all(val)); reverse(all(val)); for(int i = 0; i < sz(val); i++){ if(d[v] > k){ d[v] -= val[i]; ans++; } else break; } } int main(){ cin >> n >> k; for(int i = 1; i <= n; i++){ cin >> a[i]; } for(int i = 1; i < n; i++){ int u, v; cin >> u >> v; g[u].pb(v); g[v].pb(u); } dfs(1, 0); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...