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;
vector<pair<int,long long> > adj[300005];
long long dp(int x){
long long ret=0;
for(auto i:adj[x]){
ret+=max(dp(i.first)+i.second,0ll);
}
return ret;
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
long long n,m;
cin >> n >> m;
for(int i=1; i<=n; i++){
long long a,b;
cin >> a >> b;
adj[b].push_back({i,a});
}
cout << dp(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... |