제출 #1051327

#제출 시각아이디문제언어결과실행 시간메모리
1051327pravcoderJobs (BOI24_jobs)C++17
0 / 100
59 ms18504 KiB
#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> #include <string> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> v2i; typedef pair<int, int> pi; typedef vector<ll> vl; typedef vector<vl> v2l; #define pb push_back #define mp make_pair #define rep(i, n) for (int i = 0; i < n; i++) //sub 1 vl p; v2i adj; ll dfs(int x) { // use dfs to find the maximum possible profit given that you do job x if (adj[x].size() == 0) { return p[x]; } else { ll s = 0; for (auto a : adj[x]) { s += max(0ll, dfs(a)); } return s + p[x]; } } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; ll s; cin >> n >> s; adj.resize(n+1); p.pb(s); int x, p_i; rep(i, n) { cin >> x >> p_i; adj[p_i].pb(i+1); p.pb(x); } cout << dfs(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...