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

#TimeUsernameProblemLanguageResultExecution timeMemory
319095FoxyyPaprike (COI18_paprike)C++14
100 / 100
89 ms19576 KiB
#define DEBUG #include <bits/stdc++.h> using namespace std; const int MAXN = 100000; const int INF = 0x3f3f3f3f, MOD = 1000000007; #define INIT(arr, val) fill(arr, arr+(int)(sizeof(arr)/sizeof(arr[0])), val) #define REP(i, lb, rb, inc) for(int i = (lb); i < (rb); i += inc) #define RREP(i, rb, lb, dec) for(int i = (rb)-1; i >= (lb); i -= dec) typedef long long ll; #define sz size() typedef stack<int, vector<int> > SI; typedef queue<int> QI; typedef vector<int> VI; #define pb push_back typedef pair<int, int> PII; #define mp make_pair #define F first #define S second #define endl '\n' #define dbg(a, b) cerr << "dbg: a " << b << endl; #define dbg_itv(a, b, c) cerr << "dbg_itv: " << a << " " << b << " : " << c << endl #define IOS() cin.tie(0); cout.sync_with_stdio(0) int n, k; int ans; ll w[MAXN]; VI g[MAXN]; // solve() returns the maximum cost of the child tree ll solve(int u = 0, int anc = 0) { vector<ll> chld; for (int v : g[u]) { if (v == anc) continue; ll ret = solve(v, u); chld.pb(ret); } ll cur = w[u]; sort(chld.begin(), chld.end()); REP(i, 0, chld.size(), 1) { cur += chld[i]; if (cur > k) { cur -= chld[i]; ans += (chld.size()-i); break; } } return cur; } signed main() { IOS(); cin >> n >> k; REP(i, 0, n, 1) cin >> w[i]; int u, v; REP(i, 0, n-1, 1) { cin >> u >> v; u--, v--; g[u].pb(v); g[v].pb(u); } solve(); cout << ans << endl; }

Compilation message (stderr)

paprike.cpp: In function 'll solve(int, int)':
paprike.cpp:9:49: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 | #define REP(i, lb, rb, inc) for(int i = (lb); i < (rb); i += inc)
      |                                                 ^
paprike.cpp:43:2: note: in expansion of macro 'REP'
   43 |  REP(i, 0, chld.size(), 1) {
      |  ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...