(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 #675170

#TimeUsernameProblemLanguageResultExecution timeMemory
675170CookiePaprike (COI18_paprike)C++14
100 / 100
57 ms21084 KiB
#include<bits/stdc++.h> using namespace std; #include<fstream> #define ll long long #define vt vector #define pb push_back #define fi first #define se second #define forr(i, a, b) for(int i = a; i < b; i++) #define dorr(i, a, b) for(int i = a; i >= b; i--) typedef unsigned long long ull; #define pii pair<int, int> #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") const ll mod= 1e9 + 7; const int mxk = 1e3, sq = 750, mxn = 1e5; const ll inf = -1e18; ll n, k; ll d[mxn + 1], w[mxn + 1], a[mxn + 1]; vt<int>adj[mxn + 1]; void dfs(int s, int pre){ vt<ll>v; d[s] = 0; for(auto i: adj[s]){ if(i != pre){ dfs(i, s); d[s] += d[i]; v.pb(w[i]); } } sort(v.begin(), v.end()); w[s] = a[s]; int last = v.size(); for(int i = 0; i < v.size(); i++){ if(w[s] + v[i] <= k){ w[s] += v[i]; }else{ last = i; break; } } d[s] += v.size() - last; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for(int i = 1; i <= n; i++)cin >> a[i]; forr(i, 1, n){ int u, v; cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } dfs(1, -1); cout << d[1]; return(0); }

Compilation message (stderr)

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