Submission #1267961

#TimeUsernameProblemLanguageResultExecution timeMemory
1267961gry3125Jobs (BOI24_jobs)C++20
11 / 100
198 ms25840 KiB
#include <bits/stdc++.h> #define pb push_back #define ll long long int #define all(v) (v).begin(),(v).end() #define fi first #define se second using namespace std; vector<int> adj[300005]; vector<ll> pr(300005), memo(300005); ll dp(int v) { if (adj[v].size() == 0) { if (pr[v] <= 0) return 0LL; else return pr[v]; } if (memo[v] != 0) { return max(memo[v], 0LL); } ll sum = 0; for (auto x : adj[v]) { sum += dp(x); } memo[v] = max(sum+pr[v], -1LL); return max(sum+pr[v], 0LL); } int main() { int n; ll s; cin >> n >> s; for (int i = 1; i <= n; i++) { ll x; int p; cin >> x >> p; adj[p].pb(i); pr[i] = x; } cout << dp(0); 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...