Submission #1157180

#TimeUsernameProblemLanguageResultExecution timeMemory
1157180FilipLJobs (BOI24_jobs)C++20
11 / 100
60 ms20040 KiB
#include <bits/stdc++.h> using namespace std; #define rep(a, b) for (int a = 0; a < (b); a++) #define rep1(a, b) for (int a = 1; a <= (b); a++) #define all(x) (x).begin(), (x).end() using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int MOD = 1e9 + 7; #define LOCAL false const int LIM = 3e5 + 7; int V; ll s; int vals[LIM]; vector<int> tree[LIM]; vector<int> roots; ll calc(int v) { ll tot = vals[v]; for (int to: tree[v]) tot += max(0LL, calc(to)); return max(0LL, tot); } void pod1() { ll ans = 0; for (int r: roots) ans += calc(r); cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); if (LOCAL) { ignore=freopen("io/in", "r", stdin); ignore=freopen("io/out", "w", stdout); } cin >> V >> s; int p; rep1(v, V) { cin >> vals[v] >> p; if (p) tree[p].push_back(v); else roots.push_back(v); } if (s == 1000000000000000000LL) { pod1(); return 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...