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;
struct node {
int p;
long long x;
vector<node*> l;
};
void dfs(node* n){
for(node* c : n->l){
dfs(c);
if(c->x > 0) n->x += c->x;
}
}
void solve(){
int n;cin >> n;
long long s;cin >> s;
node g[n+1];
for(int i = 1;i <= n;i++){
cin >> g[i].x >> g[i].p;
g[g[i].p].l.push_back(&g[i]);
}
g[0].x=0;
dfs(&g[0]);
cout << g[0].x << '\n';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
}
# | 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... |