| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1286257 | ilovewaguri | Jobs (BOI24_jobs) | C++20 | 43 ms | 7552 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]);
}
return dp[u];
}
void sol() {
kahnTopo();
mset(dp,-1);
for (int u : topo) dfs(u);
cout << *max_element(allofa(dp,n));
}
}
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]++;
}
}
if(sub1::check()) sub1::sol();
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
