This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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
ll s = p[x];
for (auto a : adj[x]) {
s += max(0ll, dfs(a));
}
return s;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
ll s;
cin >> n >> s;
if (s != 10e18) return 1;
adj.resize(n+1);
p.pb(s);
ll x, p_i;
rep(i, n) {
cin >> x >> p_i;
adj[p_i].pb(i+1);
p.pb(x);
}
cout << dfs(0) << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |