제출 #1055685

#제출 시각아이디문제언어결과실행 시간메모리
1055685syxm1Jobs (BOI24_jobs)C++17
11 / 100
77 ms32592 KiB
#include<bits/stdc++.h> using namespace std; #define int long long /* - the graph will be 'c' connected components with each cc is a tree - we can process each cc individually - greedy : only take a negative node if it's child can make sum that cover loss from the current node. */ const int mxn = 3e5+20; int n, s, x[mxn], dp[mxn]; vector<int> adj[mxn]; void dfs(int cur) { int sigma = 0; for (int nxt : adj[cur]) { dfs(nxt); sigma += dp[nxt]; } dp[cur] = max(0ll, sigma + x[cur]); } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> s; for (int i = 1; i <= n; i++) { cin >> x[i]; int p; cin >> p; adj[p].push_back(i); } dfs(0); cout << dp[0] << '\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...