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 <iostream>
#include <bits/stdc++.h>
#include <map>
#include <vector>
#include <cmath>
#include <algorithm>
#include <unistd.h>
#include <cstdio>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef pair<ll, int> pil;
typedef vector<int> vi;
typedef long long ll;
typedef pair<ll,ll> pll;
const int SS = 1007;
class Solution{
public:
ll N, S, xi, pi;
vector<ll> profit = {0},
childs[SS];
ll helper(ll curr){
ll res = profit[curr];
for (auto& i: childs[curr]){
res += helper(i);
}
return max(res, 0LL);
}
ll profitProfit(){
cin >> N >> S;
for (int i = 1; i <= N; i++){
cin >> xi >> pi;
childs[pi].push_back(i);
profit.push_back( xi );
}
return helper(0);
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
Solution p;
cout << p.profitProfit();
}
# | 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... |