Submission #1095131

#TimeUsernameProblemLanguageResultExecution timeMemory
1095131epicci23Jobs (BOI24_jobs)C++17
14 / 100
5 ms860 KiB
#include "bits/stdc++.h" #define int long long #define all(v) v.begin() , v.end() #define sz(a) (int)a.size() using namespace std; const int N = 2e3 + 5; const int INF = 1e18; int n,s; vector<int> v[N]; int par[N],ar[N],vis[N]; int bak=-1,xd=0; void dfs(int c=0LL,int mini=0LL,int cur=0LL){ if(mini<-s) return; if(mini>=-s && cur>=xd && !vis[c]){ xd=cur; bak=c; } for(int x:v[c]) dfs(x,min(mini,cur+ar[x]),cur+ar[x]); } void _(){ cin >> n >> s; int lol=s; for(int i=1;i<=n;i++){ cin >> ar[i] >> par[i]; v[par[i]].push_back(i); } vis[0]=1; while(true){ bak=-1;xd=0; dfs(); if(bak==-1) break; int c=bak; while(c>0){ s+=ar[c]; ar[c]=0; vis[c]=1; c=par[c]; } } cout << s-lol << '\n'; } int32_t main(){ cin.tie(0); ios::sync_with_stdio(0); int tc=1;//cin >> tc; while(tc--) _(); return 0; }
#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...