이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 < 10e17) 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) - s << 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... |