Submission #1286256

#TimeUsernameProblemLanguageResultExecution timeMemory
1286256ilovewaguriJobs (BOI24_jobs)C++20
0 / 100
41 ms7592 KiB
#include<bits/stdc++.h>
using namespace std;
#define NAME "TEST"
#define nl '\n'
#define allofa(x,sz) x,x+sz+1
#define allof(x) x.begin(),x.end()
#define mset(x,val) memset(x,val,sizeof(x))
template<class X,class Y> bool minimize(X &a, Y b){if(a>b){a=b;return true;}return false;};
template<class X,class Y> bool maximize(X &a, Y b){if(a<b){a=b;return true;}return false;};
typedef long long ll;
const ll mod = (long long)1e9+7;
const ll LINF = (long long)1e18;
const int INF = (int)1e9;
const int MAXN = (int)3e5+5;
vector<int> graph[MAXN];
int a[MAXN],p[MAXN];
int n;ll s;

void ccps() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    if(fopen(NAME".inp","r")) {
        freopen(NAME".inp","r",stdin);
        freopen(NAME".out","w",stdout);
    }
}

namespace sub1 {
    ll res = 0;
    int inDegree[MAXN];
    vector<int> topo;
    ll dp[MAXN];

    bool check() {
        return s==1e18;
    }

    void kahnTopo() {
        queue<int> q;
        for (int u = 1; u<=n; u++) {
            if(!inDegree[u]) q.push(u);
        }
        while(!q.empty()) {
            int u = q.front();q.pop();
            topo.push_back(u);
            for (int v : graph[u]) {
                inDegree[v]--;
                if(!inDegree[v]) {
                    q.push(v);
                }
            }
        }
    }

    ll dfs(int u) {
        if(dp[u]!=-1) return dp[u];
        dp[u]=a[u];
        for (int v : graph[u]) {
            dfs(v);
            maximize(dp[u],dp[v]+a[u]);
        }
        maximize(res,dp[u]-s);
        return dp[u];
    }

    void sol() {
        res = 0;
        kahnTopo();
        mset(dp,-1);
        for (int u : topo) dfs(u);
        cout << res;
    }
}

signed main() {
    ccps();
    cin >> n >> s;
    for (int i = 1; i<=n; i++) {
        cin >> a[i] >> p[i];
        if(!p[i]) {
            graph[p[i]].push_back(i);
            sub1::inDegree[i]++;
        }
    }
    sub1::sol();
}

Compilation message (stderr)

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