Submission #1050093

#TimeUsernameProblemLanguageResultExecution timeMemory
1050093NeroZeinJobs (BOI24_jobs)C++17
11 / 100
94 ms32592 KiB
#include "bits/stdc++.h" using namespace std; #ifdef Nero #include "Deb.h" #else #define debug(...) #endif const int N = 3e5 + 5; int x[N]; int p[N]; vector<int> g[N]; long long sum[N]; void dfs(int v) { sum[v] = x[v]; for (int u : g[v]) { dfs(u); sum[v] += max(sum[u], 0LL); } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; long long s; cin >> n >> s; for (int i = 1; i <= n; ++i) { cin >> x[i] >> p[i]; g[p[i]].push_back(i); } long long cur = s; for (int i = 1; i <= n; ++i) { if (p[i] == 0) { dfs(i); cur += max(0LL, sum[i]); } } cout << cur - s << '\n'; 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...