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

Submission #693273

#TimeUsernameProblemLanguageResultExecution timeMemory
693273vuavisaoPaprike (COI18_paprike)C++14
100 / 100
73 ms38316 KiB
#include<bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define ll long long using namespace std; const ll N = 1e6 + 10; ll n, k; ll a[N]; vector<ll> g[N]; ll cost[N]; ll res; void dfs(ll u, ll p) { cost[u] = a[u]; for(const auto& v : g[u]) { if(v == p) continue; dfs(v, u); } sort(g[u].begin(), g[u].end(), [&] (ll lhs, ll rhs) -> bool { return cost[lhs] < cost[rhs]; }); ll need = (ll) g[u].size(); for(const auto& v : g[u]) { if(v == p) { -- need; continue; } if(cost[u] + cost[v] <= k) { cost[u] += cost[v]; -- need; } } res += need; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("COI18_PAPRIKE.inp", "r")) { freopen("COI18_PAPRIKE.inp", "r", stdin); freopen("COI18_PAPRIKE.out", "w", stdout); } cin >> n >> k; for(ll i = 1; i <= n; ++ i) cin >> a[i]; for(ll i = 2; i <= n; ++ i) { ll u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } dfs(1, 0); cout << res; return 0; } /// Code by vuavisao

Compilation message (stderr)

paprike.cpp: In function 'int32_t main()':
paprike.cpp:44:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         freopen("COI18_PAPRIKE.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
paprike.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         freopen("COI18_PAPRIKE.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...