Submission #1051053

#TimeUsernameProblemLanguageResultExecution timeMemory
1051053GusterGoose27Jobs (BOI24_jobs)C++17
11 / 100
59 ms28244 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5+5; typedef long long ll; const ll inf = 1e18; int n; vector<int> nxt[MAXN]; ll val[MAXN]; ll mx_val[MAXN]; ll dfs(int cur) { ll res = 0; for (int v: nxt[cur]) { res += dfs(v); } return max(0ll,res+val[cur]); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll s; cin >> n >> s; assert(s == inf); vector<int> rts; for (int i = 0; i < n; i++) { int p; cin >> val[i] >> p; if (p == 0) rts.push_back(i); else nxt[p-1].push_back(i); } ll ans = 0; for (int i: rts) ans += dfs(i); cout << ans << '\n'; }
#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...