제출 #1115696

#제출 시각아이디문제언어결과실행 시간메모리
1115696dynam1cJobs (BOI24_jobs)C++17
11 / 100
201 ms30268 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll n, s; cin >> n >> s; vector<vector<int>> graph(n); vector<int> val(n), up(n); for (int i = 0; i < n; i++) { cin >> val[i] >> up[i]; if (up[i]--) graph[up[i]].push_back(i); } function<ll(int)> dfs = [&](int v) { ll best = val[v]; for (auto ne : graph[v]) best += dfs(ne); return max(0LL, best); }; ll ans = 0; for (int i = 0; i < n; i++) if (up[i] == -1) ans += dfs(i); cout << ans << endl; }
#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...