Submission #1269549

#TimeUsernameProblemLanguageResultExecution timeMemory
1269549minggaJobs (BOI24_jobs)C++20
100 / 100
225 ms60232 KiB
// Author: caption_mingle #include "bits/stdc++.h" using namespace std; #define ln "\n" #define pb push_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define ll long long const int mod = 1e9 + 7; const int inf = 2e9; const int N = 3e5 + 7; int n; ll s; int d[N], p[N]; vector<int> g[N]; struct sus { ll req, summ; bool operator < (const sus& o) const { if(req == o.req) { return summ > o.summ; } return req > o.req; } }; priority_queue<sus> pq[N]; void dfs(int u) { for(int v : g[u]) { dfs(v); if(sz(pq[v]) > sz(pq[u])) swap(pq[v], pq[u]); while(sz(pq[v])) { pq[u].push(pq[v].top()); pq[v].pop(); } } sus neww = {max(0, -d[u]), d[u]}; while(sz(pq[u])) { auto cur = pq[u].top(); if(neww.summ < 0) { neww.req = max(neww.req, cur.req - neww.summ); neww.summ += cur.summ; pq[u].pop(); } else { if(neww.req > cur.req) { pq[u].pop(); neww.summ += cur.summ; } else { pq[u].push(neww); break; } } } if(sz(pq[u]) == 0) pq[u].push(neww); if(sz(pq[u]) == 1 and pq[u].top().summ <= 0) pq[u].pop(); } signed main() { cin.tie(0) -> sync_with_stdio(0); #define task "" if(fopen(task ".INP", "r")) { freopen(task ".INP", "r", stdin); freopen(task ".OUT", "w", stdout); } cin >> n >> s; for(int i = 1; i <= n; i++) { cin >> d[i] >> p[i]; g[p[i]].pb(i); } dfs(0); ll ans = 0; while(sz(pq[0])) { auto cur = pq[0].top(); pq[0].pop(); // cerr << cur.req << ' ' << cur.summ << ln; if(s + ans >= cur.req) { ans += cur.summ; } } cout << ans << ln; cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen(task ".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         freopen(task ".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...
#Verdict Execution timeMemoryGrader output
Fetching results...