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<bits/stdc++.h>
using namespace std;
const int MAX_N = 3e5+1;
int N, S;
vector<int> ch[MAX_N];
int x[MAX_N];
int dfs(int u){
int res= 0;
res += x[u];
for(auto e: ch[u]){
res += dfs(e);
}
return max(0, res);
}
signed main(){
cin>>N>>S;
x[0] = 0;
for(int i = 1; i<=N; i++){
int anc;
cin>>x[i]>>anc;
ch[anc].push_back(i);
}
cout<<dfs(0)<<endl;
}
# | 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... |