제출 #1254179

#제출 시각아이디문제언어결과실행 시간메모리
1254179BuiDucManh123Jobs (BOI24_jobs)C++20
100 / 100
204 ms80200 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define taskname ""
#define ld long double
const int mod = 1e9+7;
using namespace std;
#define int ll
const int inf = 2e18;
const int N = 3e5;
int x[300009], cost[300009], win[N + 9];
vector<int> g[300009];
priority_queue<pii, vector<pii>, greater<>> q[N + 9];
void dfs(int u){
    for(int v : g[u]){
        dfs(v);
    }
    q[u].push({0, u});
    int cur = 0;
    while(!q[u].empty()){
        pii v = q[u].top();
        q[u].pop();
        if(v.fi == inf) break;
        if(cur < v.fi){
            cost[u] += v.fi - cur;
            cur = v.fi;
        }
        if(v.se == u){
            cur += x[u];
            for(int k : g[u]){
                q[u].push({cost[k], k});
            }
        }else{
            cur += win[v.se];
            if(q[u].size() < q[v.se].size()) swap(q[u], q[v.se]);
            while(!q[v.se].empty()){
                q[u].push(q[v.se].top());
                q[v.se].pop();
            }
        }
        if(cur >= cost[u]){
            win[u] = cur - cost[u];
            return;
        }
    }
    cost[u] = inf;
}
signed main() {
    if (fopen(taskname".inp","r")) {
        freopen(taskname".inp","r",stdin);
        freopen(taskname".out","w",stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, s;
    cin >> n >> s;
    for(int i = 1; i <= n; i++){
        int p;
        cin >> x[i] >> p;
        g[p].pb(i);
    }
    dfs(0);
    /*
    for(int i = 0; i <= n; i++){
        cout << cost[i] << "\n";
    }
    */
    priority_queue<pii, vector<pii>, greater<>> pq;
    pq.push({cost[0], 0});
    int profit = s;
    while(!pq.empty()){
        pii u = pq.top();
        pq.pop();
        if(profit < u.fi){
            break;
        }
        profit += x[u.se];
        for(int v : g[u.se]){
            pq.push({cost[v], v});
        }
    }
    cout << profit - s;
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         freopen(taskname".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         freopen(taskname".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...